aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / libc / src / new / qurt / pthread.rs
| 1 | //! Header: `pthread.h` |
| 2 | //! |
| 3 | //! QuRT provides a subset of POSIX pthread functionality optimized for real-time systems. |
| 4 | |
| 5 | use super::*; |
| 6 | use crate::prelude::*; |
| 7 | |
| 8 | // Thread creation attributes (QuRT values differ from POSIX/Linux defaults) |
| 9 | pub const PTHREAD_CREATE_DETACHED: c_int = 0; |
| 10 | pub const PTHREAD_CREATE_JOINABLE: c_int = 1; |
| 11 | |
| 12 | // Mutex types (QuRT values differ from POSIX/Linux defaults) |
| 13 | pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 0; |
| 14 | pub const PTHREAD_MUTEX_NORMAL: c_int = 1; |
| 15 | pub const PTHREAD_MUTEX_RECURSIVE: c_int = 2; |
| 16 | pub const PTHREAD_MUTEX_DEFAULT: c_int = 3; |
| 17 | |
| 18 | // Process sharing |
| 19 | pub const PTHREAD_PROCESS_PRIVATE: c_int = 0; |
| 20 | pub const PTHREAD_PROCESS_SHARED: c_int = 1; |
| 21 | |
| 22 | // Mutex protocol |
| 23 | pub const PTHREAD_PRIO_NONE: c_int = 0; |
| 24 | pub const PTHREAD_PRIO_INHERIT: c_int = 1; |
| 25 | pub const PTHREAD_PRIO_PROTECT: c_int = 2; |
| 26 | |
| 27 | // Thread priority constants |
| 28 | pub const PTHREAD_MIN_PRIORITY: c_int = 0; |
| 29 | pub const PTHREAD_MAX_PRIORITY: c_int = 255; |
| 30 | |
| 31 | // Initializer constants |
| 32 | pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = 0xFFFFFFFF; |
| 33 | pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0xFFFFFFFF; |
| 34 | pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = !0usize as pthread_rwlock_t; |
| 35 | pub const PTHREAD_ONCE_INIT: pthread_once_t = 0; |
| 36 | |
| 37 | // Stack size |
| 38 | pub const PTHREAD_STACK_MIN: size_t = 8192; |
| 39 | |
| 40 | // Contention scope |
| 41 | pub const PTHREAD_SCOPE_SYSTEM: c_int = 0; |
| 42 | pub const PTHREAD_SCOPE_PROCESS: c_int = 1; |
| 43 | |
| 44 | // Scheduler inheritance (QuRT values differ from POSIX/Linux defaults) |
| 45 | pub const PTHREAD_EXPLICIT_SCHED: c_int = 0; |
| 46 | pub const PTHREAD_INHERIT_SCHED: c_int = 1; |
| 47 | |
| 48 | extern "C" { |
| 49 | // Thread management |
| 50 | pub fn pthread_create( |
| 51 | thread: *mut pthread_t, |
| 52 | attr: *const pthread_attr_t, |
| 53 | start_routine: extern "C" fn(*mut c_void) -> *mut c_void, |
| 54 | arg: *mut c_void, |
| 55 | ) -> c_int; |
| 56 | pub fn pthread_join(thread: pthread_t, retval: *mut *mut c_void) -> c_int; |
| 57 | pub fn pthread_detach(thread: pthread_t) -> c_int; |
| 58 | pub fn pthread_exit(retval: *mut c_void) -> !; |
| 59 | pub fn pthread_self() -> pthread_t; |
| 60 | // Note: pthread_equal is static inline in QuRT pthread.h, no linkable symbol |
| 61 | pub fn pthread_cancel(thread: pthread_t) -> c_int; |
| 62 | pub fn pthread_kill(thread: pthread_t, sig: c_int) -> c_int; |
| 63 | pub fn pthread_setcancelstate(state: c_int, oldstate: *mut c_int) -> c_int; |
| 64 | pub fn pthread_setcanceltype(r#type: c_int, oldtype: *mut c_int) -> c_int; |
| 65 | |
| 66 | // Thread scheduling |
| 67 | pub fn pthread_getschedparam( |
| 68 | thread: pthread_t, |
| 69 | policy: *mut c_int, |
| 70 | param: *mut sched_param, |
| 71 | ) -> c_int; |
| 72 | pub fn pthread_setschedparam( |
| 73 | thread: pthread_t, |
| 74 | policy: c_int, |
| 75 | param: *const sched_param, |
| 76 | ) -> c_int; |
| 77 | pub fn pthread_setschedprio(thread: pthread_t, prio: c_int) -> c_int; |
| 78 | |
| 79 | // Thread attributes |
| 80 | pub fn pthread_attr_init(attr: *mut pthread_attr_t) -> c_int; |
| 81 | pub fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> c_int; |
| 82 | pub fn pthread_attr_setstacksize(attr: *mut pthread_attr_t, stacksize: size_t) -> c_int; |
| 83 | pub fn pthread_attr_getstacksize(attr: *const pthread_attr_t, stacksize: *mut size_t) -> c_int; |
| 84 | pub fn pthread_attr_setstackaddr(attr: *mut pthread_attr_t, stackaddr: *mut c_void) -> c_int; |
| 85 | pub fn pthread_attr_getstackaddr( |
| 86 | attr: *const pthread_attr_t, |
| 87 | stackaddr: *mut *mut c_void, |
| 88 | ) -> c_int; |
| 89 | pub fn pthread_attr_setstack( |
| 90 | attr: *mut pthread_attr_t, |
| 91 | stackaddr: *mut c_void, |
| 92 | stacksize: size_t, |
| 93 | ) -> c_int; |
| 94 | pub fn pthread_attr_getstack( |
| 95 | attr: *const pthread_attr_t, |
| 96 | stackaddr: *mut *mut c_void, |
| 97 | stacksize: *mut size_t, |
| 98 | ) -> c_int; |
| 99 | pub fn pthread_attr_setdetachstate(attr: *mut pthread_attr_t, detachstate: c_int) -> c_int; |
| 100 | pub fn pthread_attr_getdetachstate( |
| 101 | attr: *const pthread_attr_t, |
| 102 | detachstate: *mut c_int, |
| 103 | ) -> c_int; |
| 104 | pub fn pthread_attr_setscope(attr: *mut pthread_attr_t, scope: c_int) -> c_int; |
| 105 | pub fn pthread_attr_getscope(attr: *const pthread_attr_t, scope: *mut c_int) -> c_int; |
| 106 | pub fn pthread_attr_setinheritsched(attr: *mut pthread_attr_t, inheritsched: c_int) -> c_int; |
| 107 | pub fn pthread_attr_getinheritsched( |
| 108 | attr: *const pthread_attr_t, |
| 109 | inheritsched: *mut c_int, |
| 110 | ) -> c_int; |
| 111 | pub fn pthread_attr_setschedparam( |
| 112 | attr: *mut pthread_attr_t, |
| 113 | param: *const sched_param, |
| 114 | ) -> c_int; |
| 115 | pub fn pthread_attr_getschedparam( |
| 116 | attr: *const pthread_attr_t, |
| 117 | param: *mut sched_param, |
| 118 | ) -> c_int; |
| 119 | pub fn pthread_attr_getguardsize(attr: *const pthread_attr_t, guardsize: *mut size_t) -> c_int; |
| 120 | |
| 121 | // Mutex operations |
| 122 | pub fn pthread_mutex_init( |
| 123 | mutex: *mut pthread_mutex_t, |
| 124 | attr: *const pthread_mutexattr_t, |
| 125 | ) -> c_int; |
| 126 | pub fn pthread_mutex_destroy(mutex: *mut pthread_mutex_t) -> c_int; |
| 127 | pub fn pthread_mutex_lock(mutex: *mut pthread_mutex_t) -> c_int; |
| 128 | pub fn pthread_mutex_trylock(mutex: *mut pthread_mutex_t) -> c_int; |
| 129 | pub fn pthread_mutex_unlock(mutex: *mut pthread_mutex_t) -> c_int; |
| 130 | pub fn pthread_mutex_getprioceiling( |
| 131 | mutex: *const pthread_mutex_t, |
| 132 | prioceiling: *mut c_int, |
| 133 | ) -> c_int; |
| 134 | pub fn pthread_mutex_setprioceiling( |
| 135 | mutex: *mut pthread_mutex_t, |
| 136 | prioceiling: c_int, |
| 137 | old_ceiling: *mut c_int, |
| 138 | ) -> c_int; |
| 139 | |
| 140 | // Mutex attributes |
| 141 | pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> c_int; |
| 142 | pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> c_int; |
| 143 | pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t, kind: c_int) -> c_int; |
| 144 | pub fn pthread_mutexattr_gettype(attr: *const pthread_mutexattr_t, kind: *mut c_int) -> c_int; |
| 145 | pub fn pthread_mutexattr_setprotocol(attr: *mut pthread_mutexattr_t, protocol: c_int) -> c_int; |
| 146 | pub fn pthread_mutexattr_getprotocol( |
| 147 | attr: *const pthread_mutexattr_t, |
| 148 | protocol: *mut c_int, |
| 149 | ) -> c_int; |
| 150 | pub fn pthread_mutexattr_setpshared(attr: *mut pthread_mutexattr_t, pshared: c_int) -> c_int; |
| 151 | pub fn pthread_mutexattr_getpshared( |
| 152 | attr: *const pthread_mutexattr_t, |
| 153 | pshared: *mut c_int, |
| 154 | ) -> c_int; |
| 155 | pub fn pthread_mutexattr_setprioceiling( |
| 156 | attr: *mut pthread_mutexattr_t, |
| 157 | prioceiling: c_int, |
| 158 | ) -> c_int; |
| 159 | pub fn pthread_mutexattr_getprioceiling( |
| 160 | attr: *const pthread_mutexattr_t, |
| 161 | prioceiling: *mut c_int, |
| 162 | ) -> c_int; |
| 163 | |
| 164 | // Condition variables |
| 165 | pub fn pthread_cond_init(cond: *mut pthread_cond_t, attr: *const pthread_condattr_t) -> c_int; |
| 166 | pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> c_int; |
| 167 | pub fn pthread_cond_wait(cond: *mut pthread_cond_t, mutex: *mut pthread_mutex_t) -> c_int; |
| 168 | pub fn pthread_cond_timedwait( |
| 169 | cond: *mut pthread_cond_t, |
| 170 | mutex: *mut pthread_mutex_t, |
| 171 | abstime: *const timespec, |
| 172 | ) -> c_int; |
| 173 | pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> c_int; |
| 174 | pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> c_int; |
| 175 | |
| 176 | // Condition variable attributes |
| 177 | pub fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> c_int; |
| 178 | pub fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> c_int; |
| 179 | pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t, clock_id: clockid_t) -> c_int; |
| 180 | pub fn pthread_condattr_getclock( |
| 181 | attr: *const pthread_condattr_t, |
| 182 | clock_id: *mut clockid_t, |
| 183 | ) -> c_int; |
| 184 | pub fn pthread_condattr_setpshared(attr: *mut pthread_condattr_t, pshared: c_int) -> c_int; |
| 185 | pub fn pthread_condattr_getpshared( |
| 186 | attr: *const pthread_condattr_t, |
| 187 | pshared: *mut c_int, |
| 188 | ) -> c_int; |
| 189 | |
| 190 | // Spinlocks |
| 191 | pub fn pthread_spin_init(lock: *mut pthread_spinlock_t, pshared: c_int) -> c_int; |
| 192 | pub fn pthread_spin_destroy(lock: *mut pthread_spinlock_t) -> c_int; |
| 193 | pub fn pthread_spin_lock(lock: *mut pthread_spinlock_t) -> c_int; |
| 194 | pub fn pthread_spin_trylock(lock: *mut pthread_spinlock_t) -> c_int; |
| 195 | pub fn pthread_spin_unlock(lock: *mut pthread_spinlock_t) -> c_int; |
| 196 | |
| 197 | // Barriers |
| 198 | pub fn pthread_barrier_init( |
| 199 | barrier: *mut pthread_barrier_t, |
| 200 | attr: *const pthread_barrierattr_t, |
| 201 | count: c_uint, |
| 202 | ) -> c_int; |
| 203 | pub fn pthread_barrier_destroy(barrier: *mut pthread_barrier_t) -> c_int; |
| 204 | pub fn pthread_barrier_wait(barrier: *mut pthread_barrier_t) -> c_int; |
| 205 | pub fn pthread_barrierattr_init(attr: *mut pthread_barrierattr_t) -> c_int; |
| 206 | pub fn pthread_barrierattr_destroy(attr: *mut pthread_barrierattr_t) -> c_int; |
| 207 | pub fn pthread_barrierattr_getpshared( |
| 208 | attr: *const pthread_barrierattr_t, |
| 209 | pshared: *mut c_int, |
| 210 | ) -> c_int; |
| 211 | pub fn pthread_barrierattr_setpshared( |
| 212 | attr: *mut pthread_barrierattr_t, |
| 213 | pshared: c_int, |
| 214 | ) -> c_int; |
| 215 | |
| 216 | // Read-write locks |
| 217 | pub fn pthread_rwlock_init( |
| 218 | rwlock: *mut pthread_rwlock_t, |
| 219 | attr: *const pthread_rwlockattr_t, |
| 220 | ) -> c_int; |
| 221 | pub fn pthread_rwlock_destroy(rwlock: *mut pthread_rwlock_t) -> c_int; |
| 222 | pub fn pthread_rwlock_rdlock(rwlock: *mut pthread_rwlock_t) -> c_int; |
| 223 | pub fn pthread_rwlock_tryrdlock(rwlock: *mut pthread_rwlock_t) -> c_int; |
| 224 | pub fn pthread_rwlock_wrlock(rwlock: *mut pthread_rwlock_t) -> c_int; |
| 225 | pub fn pthread_rwlock_trywrlock(rwlock: *mut pthread_rwlock_t) -> c_int; |
| 226 | pub fn pthread_rwlock_unlock(rwlock: *mut pthread_rwlock_t) -> c_int; |
| 227 | pub fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) -> c_int; |
| 228 | pub fn pthread_rwlockattr_destroy(attr: *mut pthread_rwlockattr_t) -> c_int; |
| 229 | pub fn pthread_rwlockattr_getpshared( |
| 230 | attr: *const pthread_rwlockattr_t, |
| 231 | pshared: *mut c_int, |
| 232 | ) -> c_int; |
| 233 | pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t, pshared: c_int) -> c_int; |
| 234 | |
| 235 | // Thread-local storage |
| 236 | pub fn pthread_key_create( |
| 237 | key: *mut pthread_key_t, |
| 238 | destructor: Option<extern "C" fn(*mut c_void)>, |
| 239 | ) -> c_int; |
| 240 | pub fn pthread_key_delete(key: pthread_key_t) -> c_int; |
| 241 | pub fn pthread_getspecific(key: pthread_key_t) -> *mut c_void; |
| 242 | pub fn pthread_setspecific(key: pthread_key_t, value: *const c_void) -> c_int; |
| 243 | |
| 244 | // One-time initialization |
| 245 | pub fn pthread_once(once_control: *mut pthread_once_t, init_routine: extern "C" fn()) -> c_int; |
| 246 | |
| 247 | // GNU/QuRT non-portable extensions |
| 248 | pub fn pthread_getname_np(thread: pthread_t, name: *mut c_char, len: size_t) -> c_int; |
| 249 | pub fn pthread_getattr_np(thread: pthread_t, attr: *mut pthread_attr_t) -> c_int; |
| 250 | pub fn pthread_attr_setaffinity_np( |
| 251 | attr: *mut pthread_attr_t, |
| 252 | cpusetsize: size_t, |
| 253 | cpuset: *const cpu_set_t, |
| 254 | ) -> c_int; |
| 255 | pub fn pthread_attr_getaffinity_np( |
| 256 | attr: *mut pthread_attr_t, |
| 257 | cpusetsize: size_t, |
| 258 | cpuset: *mut cpu_set_t, |
| 259 | ) -> c_int; |
| 260 | |
| 261 | // QuRT-specific thread attribute extensions |
| 262 | pub fn pthread_attr_setthreadname(attr: *mut pthread_attr_t, name: *const c_char) -> c_int; |
| 263 | pub fn pthread_attr_getthreadname( |
| 264 | attr: *const pthread_attr_t, |
| 265 | name: *mut c_char, |
| 266 | size: c_int, |
| 267 | ) -> c_int; |
| 268 | pub fn pthread_attr_settimetestid(attr: *mut pthread_attr_t, tid: c_uint) -> c_int; |
| 269 | pub fn pthread_attr_gettimetestid(attr: *const pthread_attr_t, tid: *mut c_uint) -> c_int; |
| 270 | pub fn pthread_attr_setautostack(attr: *mut pthread_attr_t) -> c_int; |
| 271 | pub fn pthread_attr_setbuspriority(attr: *mut pthread_attr_t, bus_priority: c_ushort) -> c_int; |
| 272 | |
| 273 | // POSIX standard (declared in QuRT pthread.h) |
| 274 | pub fn posix_memalign(memptr: *mut *mut c_void, alignment: size_t, size: size_t) -> c_int; |
| 275 | } |