pthread.odin 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. #+build linux, darwin, netbsd, openbsd, freebsd
  2. package posix
  3. import "core:c"
  4. when ODIN_OS == .Darwin {
  5. foreign import lib "system:System.framework"
  6. } else when ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .Linux {
  7. foreign import lib "system:pthread"
  8. } else {
  9. foreign import lib "system:c"
  10. }
  11. // pthread.h - threads
  12. // NOTE: mutexes, rwlock, condition variables, once and barriers are left out in favour of `core:sync`.
  13. foreign lib {
  14. /*
  15. Initializes a thread attributes object.
  16. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_init.html ]]
  17. */
  18. pthread_attr_init :: proc(attr: ^pthread_attr_t) -> Errno ---
  19. /*
  20. Destroys a thread attributes object.
  21. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_init.html ]]
  22. */
  23. pthread_attr_destroy :: proc(attr: ^pthread_attr_t) -> Errno ---
  24. /*
  25. The detachstate attribute controls whether the thread is created in a detached state.
  26. If the thread is created detached, then use of the ID of the newly created thread is an error.
  27. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getdetachstate.html ]]
  28. */
  29. pthread_attr_getdetachstate :: proc(attr: ^pthread_attr_t, detachstate: ^Detach_State) -> Errno ---
  30. /*
  31. The detachstate attribute controls whether the thread is created in a detached state.
  32. If the thread is created detached, then use of the ID of the newly created thread is an error.
  33. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getdetachstate.html ]]
  34. */
  35. pthread_attr_setdetachstate :: proc(attr: ^pthread_attr_t, detachstate: Detach_State) -> Errno ---
  36. /*
  37. The guardsize attribute controls the size of the guard area for the created thread's stack.
  38. The guardsize attribute provides protection against overflow of the stack pointer.
  39. If a thread's stack is created with guard protection, the implementation allocates extra memory
  40. at the overflow end of the stack as a buffer against stack overflow of the stack pointer.
  41. If an application overflows into this buffer an error shall result (possibly in a SIGSEGV signal being delivered to the thread).
  42. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setguardsize.html ]]
  43. */
  44. pthread_attr_getguardsize :: proc(attr: ^pthread_attr_t, guardsize: ^c.size_t) -> Errno ---
  45. /*
  46. The guardsize attribute controls the size of the guard area for the created thread's stack.
  47. The guardsize attribute provides protection against overflow of the stack pointer.
  48. If a thread's stack is created with guard protection, the implementation allocates extra memory
  49. at the overflow end of the stack as a buffer against stack overflow of the stack pointer.
  50. If an application overflows into this buffer an error shall result (possibly in a SIGSEGV signal being delivered to the thread).
  51. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setguardsize.html ]]
  52. */
  53. pthread_attr_setguardsize :: proc(attr: ^pthread_attr_t, guardsize: c.size_t) -> Errno ---
  54. /*
  55. When the attributes objects are used by pthread_create(), the inheritsched attribute determines
  56. how the other scheduling attributes of the created thread shall be set.
  57. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setinheritsched.html ]]
  58. */
  59. pthread_attr_getinheritsched :: proc(attr: ^pthread_attr_t, inheritsched: ^Inherit_Sched) -> Errno ---
  60. /*
  61. When the attributes objects are used by pthread_create(), the inheritsched attribute determines
  62. how the other scheduling attributes of the created thread shall be set.
  63. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setinheritsched.html ]]
  64. */
  65. pthread_attr_setinheritsched :: proc(attr: ^pthread_attr_t, inheritsched: Inherit_Sched) -> Errno ---
  66. /*
  67. Gets the scheduling param.
  68. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedparam.html ]]
  69. */
  70. pthread_attr_getschedparam :: proc(attr: ^pthread_attr_t, param: ^sched_param) -> Errno ---
  71. /*
  72. Sets the scheduling param.
  73. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedparam.html ]]
  74. */
  75. pthread_attr_setschedparam :: proc(attr: ^pthread_attr_t, param: ^sched_param) -> Errno ---
  76. /*
  77. Gets the scheduling poicy.
  78. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getschedpolicy.html ]]
  79. */
  80. pthread_attr_getschedpolicy :: proc(attr: ^pthread_attr_t, policy: ^Sched_Policy) -> Errno ---
  81. /*
  82. Sets the scheduling poicy.
  83. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getschedpolicy.html ]]
  84. */
  85. pthread_attr_setschedpolicy :: proc(attr: ^pthread_attr_t, policy: Sched_Policy) -> Errno ---
  86. /*
  87. Gets the contention scope.
  88. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getscope.html ]]
  89. */
  90. pthread_attr_getscope :: proc(attr: ^pthread_attr_t, contentionscope: ^Thread_Scope) -> Errno ---
  91. /*
  92. Sets the contention scope.
  93. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getscope.html ]]
  94. */
  95. pthread_attr_setscope :: proc(attr: ^pthread_attr_t, contentionscope: ^Thread_Scope) -> Errno ---
  96. /*
  97. Get the area of storage to be used for the created thread's stack.
  98. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstack.html ]]
  99. */
  100. pthread_attr_getstack :: proc(attr: ^pthread_attr_t, stackaddr: ^[^]byte, stacksize: ^c.size_t) -> Errno ---
  101. /*
  102. Specify the area of storage to be used for the created thread's stack.
  103. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstack.html ]]
  104. */
  105. pthread_attr_setstack :: proc(attr: ^pthread_attr_t, stackaddr: [^]byte, stacksize: c.size_t) -> Errno ---
  106. /*
  107. Gets the stack size.
  108. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstacksize.html ]]
  109. */
  110. pthread_attr_getstacksize :: proc(attr: ^pthread_attr_t, stacksize: ^c.size_t) -> Errno ---
  111. /*
  112. Sets the stack size.
  113. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstacksize.html ]]
  114. */
  115. pthread_attr_setstacksize :: proc(attr: ^pthread_attr_t, stacksize: c.size_t) -> Errno ---
  116. /*
  117. Register fork handlers to be called before and after fork().
  118. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_atfork.html ]]
  119. */
  120. pthread_atfork :: proc(prepare: proc "c" (), parent: proc "c" (), child: proc "c" ()) -> Errno ---
  121. /*
  122. Cancel the execution of a thread.
  123. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cancel.html ]]
  124. */
  125. pthread_cancel :: proc(thread: pthread_t) -> Errno ---
  126. /*
  127. Creates a new thread with the given attributes.
  128. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html ]]
  129. */
  130. pthread_create :: proc(
  131. thread: ^pthread_t,
  132. attr: ^pthread_attr_t,
  133. start_routine: proc "c" (arg: rawptr) -> rawptr,
  134. arg: rawptr,
  135. ) -> Errno ---
  136. /*
  137. Indicate that storage for the thread can be reclaimed when the thread terminates.
  138. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_detach.html ]]
  139. */
  140. pthread_detach :: proc(thread: pthread_t) -> Errno ---
  141. /*
  142. Compare thread IDs.
  143. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_equal.html ]]
  144. */
  145. pthread_equal :: proc(t1: pthread_t, t2: pthread_t) -> b32 ---
  146. /*
  147. Terminates the calling thread and make the given value available to any successfull join calls.
  148. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_exit.html ]]
  149. */
  150. pthread_exit :: proc(value_ptr: rawptr) -> ! ---
  151. /*
  152. Gets the current concurrency hint.
  153. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getconcurrency.html ]]
  154. */
  155. pthread_getconcurrency :: proc() -> c.int ---
  156. /*
  157. Sets the current desired concurrency hint.
  158. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getconcurrency.html ]]
  159. */
  160. pthread_setconcurrency :: proc(new_level: c.int) -> Errno ---
  161. /*
  162. Access a thread CPU-time clock.
  163. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getcpuclockid.html ]]
  164. */
  165. pthread_getcpuclockid :: proc(thread_id: pthread_t, clock_id: ^clockid_t) -> Errno ---
  166. /*
  167. Gets the scheduling policy and parameters.
  168. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getschedparam.html ]]
  169. */
  170. pthread_getschedparam :: proc(thread: pthread_t, policy: ^Sched_Policy, param: ^sched_param) -> Errno ---
  171. /*
  172. Sets the scheduling policy and parameters.
  173. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getschedparam.html ]]
  174. */
  175. pthread_setschedparam :: proc(thread: pthread_t, policy: Sched_Policy, param: ^sched_param) -> Errno ---
  176. /*
  177. Creates a thread-specific data key visible to all threads in the process.
  178. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_key_create.html ]]
  179. */
  180. pthread_key_create :: proc(key: ^pthread_key_t, destructor: proc "c" (value: rawptr) = nil) -> Errno ---
  181. /*
  182. Deletes a thread-specific data key visible to all threads in the process.
  183. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_key_delete.html ]]
  184. */
  185. pthread_key_delete :: proc(key: pthread_key_t) -> Errno ---
  186. /*
  187. Returns the value currently bound to the specified key on behalf of the calling thread.
  188. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getspecific.html ]]
  189. */
  190. pthread_getspecific :: proc(key: pthread_key_t) -> rawptr ---
  191. /*
  192. Sets the value currently bound to the specified key on behalf of the calling thread.
  193. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getspecific.html ]]
  194. */
  195. pthread_setspecific :: proc(key: pthread_key_t, value: rawptr) -> Errno ---
  196. /*
  197. Suspends execution of the calling thread until the target thread terminates.
  198. Example:
  199. ar: [10_000]i32
  200. sb1 := ar[:5_000]
  201. sb2 := ar[5_000:]
  202. th1, th2: posix.pthread_t
  203. posix.pthread_create(&th1, nil, incer, &sb1)
  204. posix.pthread_create(&th2, nil, incer, &sb2)
  205. posix.pthread_join(th1)
  206. posix.pthread_join(th2)
  207. incer :: proc "c" (arg: rawptr) -> rawptr {
  208. sb := (^[]i32)(arg)
  209. for &val in sb {
  210. val += 1
  211. }
  212. return nil
  213. }
  214. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html ]]
  215. */
  216. pthread_join :: proc(thread: pthread_t, value_ptr: ^rawptr = nil) -> Errno ---
  217. /*
  218. Get the calling thread ID.
  219. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html ]]
  220. */
  221. pthread_self :: proc() -> pthread_t ---
  222. /*
  223. Atomically set the calling thread's cancelability and return the previous value.
  224. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_setcancelstate.html ]]
  225. */
  226. pthread_setcancelstate :: proc(state: Cancel_State, oldstate: ^Cancel_State) -> Errno ---
  227. /*
  228. Atomically set the calling thread's cancel type and return the previous value.
  229. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_setcancelstate.html ]]
  230. */
  231. pthread_setcanceltype :: proc(type: Cancel_Type, oldtype: ^Cancel_Type) -> Errno ---
  232. /*
  233. Creates a cancellation point in the calling thread.
  234. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_testcancel.html ]]
  235. */
  236. pthread_testcancel :: proc() ---
  237. /*
  238. Sets the scheduling priority for the thread given.
  239. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_setschedprio.html ]]
  240. */
  241. pthread_setschedprio :: proc(thread: pthread_t, prio: c.int) -> Errno ---
  242. }
  243. Detach_State :: enum c.int {
  244. // Causes all threads to be in the joinable state.
  245. CREATE_JOINABLE = PTHREAD_CREATE_JOINABLE,
  246. // Causes all threads to be in the detached state.
  247. CREATE_DETACHED = PTHREAD_CREATE_DETACHED,
  248. }
  249. Inherit_Sched :: enum c.int {
  250. // Threads inherit from the creating thread.
  251. INHERIT_SCHED = PTHREAD_INHERIT_SCHED,
  252. // Threads scheduling shall be set to the corresponding values from the attributes object.
  253. EXPLICIT_SCHED = PTHREAD_EXPLICIT_SCHED,
  254. }
  255. Thread_Scope :: enum c.int {
  256. // System scheduling contention scope.
  257. SYSTEM = PTHREAD_SCOPE_SYSTEM,
  258. // Process scheduling contention scope.
  259. PROCESS = PTHREAD_SCOPE_PROCESS,
  260. }
  261. Cancel_State :: enum c.int {
  262. // Cancel takes place at next cancellation point.
  263. ENABLE = PTHREAD_CANCEL_ENABLE,
  264. // Cancel postponed.
  265. DISABLE = PTHREAD_CANCEL_DISABLE,
  266. }
  267. Cancel_Type :: enum c.int {
  268. // Cancel waits until cancellation point.
  269. DEFERRED = PTHREAD_CANCEL_DEFERRED,
  270. // Cancel occurs immediately.
  271. ASYNCHRONOUS = PTHREAD_CANCEL_ASYNCHRONOUS,
  272. }
  273. when ODIN_OS == .Darwin {
  274. PTHREAD_CANCEL_ASYNCHRONOUS :: 0x00
  275. PTHREAD_CANCEL_DEFERRED :: 0x02
  276. PTHREAD_CANCEL_DISABLE :: 0x00
  277. PTHREAD_CANCEL_ENABLE :: 0x01
  278. // PTHREAD_CANCEL_ASYNCHRONOUS :: 1
  279. // PTHREAD_CANCEL_DEFERRED :: 0
  280. //
  281. // PTHREAD_CANCEL_DISABLE :: 1
  282. // PTHREAD_CANCEL_ENABLE :: 0
  283. PTHREAD_CANCELED :: rawptr(uintptr(1))
  284. PTHREAD_CREATE_DETACHED :: 2
  285. PTHREAD_CREATE_JOINABLE :: 1
  286. PTHREAD_EXPLICIT_SCHED :: 2
  287. PTHREAD_INHERIT_SCHED :: 1
  288. PTHREAD_PRIO_INHERIT :: 1
  289. PTHREAD_PRIO_NONE :: 0
  290. PTHREAD_PRIO_PROTECT :: 2
  291. PTHREAD_PROCESS_SHARED :: 1
  292. PTHREAD_PROCESS_PRIVATE :: 2
  293. PTHREAD_SCOPE_PROCESS :: 2
  294. PTHREAD_SCOPE_SYSTEM :: 1
  295. pthread_t :: distinct u64
  296. pthread_attr_t :: struct {
  297. __sig: c.long,
  298. __opaque: [56]c.char,
  299. }
  300. pthread_key_t :: distinct c.ulong
  301. pthread_mutex_t :: struct {
  302. __sig: c.long,
  303. __opaque: [56]c.char,
  304. }
  305. pthread_cond_t :: struct {
  306. __sig: c.long,
  307. __opaque: [40]c.char,
  308. }
  309. sched_param :: struct {
  310. sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
  311. _: [4]c.char,
  312. }
  313. } else when ODIN_OS == .FreeBSD {
  314. PTHREAD_CANCEL_ASYNCHRONOUS :: 0x02
  315. PTHREAD_CANCEL_DEFERRED :: 0x00
  316. PTHREAD_CANCEL_DISABLE :: 0x01
  317. PTHREAD_CANCEL_ENABLE :: 0x00
  318. PTHREAD_CANCELED :: rawptr(uintptr(1))
  319. PTHREAD_CREATE_DETACHED :: 1
  320. PTHREAD_CREATE_JOINABLE :: 0
  321. PTHREAD_EXPLICIT_SCHED :: 0
  322. PTHREAD_INHERIT_SCHED :: 4
  323. PTHREAD_PRIO_INHERIT :: 1
  324. PTHREAD_PRIO_NONE :: 0
  325. PTHREAD_PRIO_PROTECT :: 2
  326. PTHREAD_PROCESS_SHARED :: 1
  327. PTHREAD_PROCESS_PRIVATE :: 0
  328. PTHREAD_SCOPE_PROCESS :: 0
  329. PTHREAD_SCOPE_SYSTEM :: 2
  330. pthread_t :: distinct u64
  331. pthread_attr_t :: struct #align(8) {
  332. _: [8]byte,
  333. }
  334. pthread_key_t :: distinct c.int
  335. pthread_mutex_t :: struct #align(8) {
  336. _: [8]byte,
  337. }
  338. pthread_cond_t :: struct #align(8) {
  339. _: [8]byte,
  340. }
  341. sched_param :: struct {
  342. sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
  343. }
  344. } else when ODIN_OS == .NetBSD {
  345. PTHREAD_CANCEL_ASYNCHRONOUS :: 1
  346. PTHREAD_CANCEL_DEFERRED :: 0
  347. PTHREAD_CANCEL_DISABLE :: 1
  348. PTHREAD_CANCEL_ENABLE :: 0
  349. PTHREAD_CANCELED :: rawptr(uintptr(1))
  350. PTHREAD_CREATE_DETACHED :: 1
  351. PTHREAD_CREATE_JOINABLE :: 0
  352. PTHREAD_EXPLICIT_SCHED :: 1
  353. PTHREAD_INHERIT_SCHED :: 0
  354. PTHREAD_PRIO_INHERIT :: 1
  355. PTHREAD_PRIO_NONE :: 0
  356. PTHREAD_PRIO_PROTECT :: 2
  357. PTHREAD_PROCESS_SHARED :: 1
  358. PTHREAD_PROCESS_PRIVATE :: 0
  359. PTHREAD_SCOPE_PROCESS :: 0
  360. PTHREAD_SCOPE_SYSTEM :: 1
  361. pthread_t :: distinct rawptr
  362. pthread_attr_t :: struct {
  363. pta_magic: c.uint,
  364. pta_flags: c.int,
  365. pta_private: rawptr,
  366. }
  367. pthread_key_t :: distinct c.int
  368. pthread_cond_t :: struct #align(8) {
  369. _: [40]byte,
  370. }
  371. pthread_mutex_t :: struct #align(8) {
  372. _: [48]byte,
  373. }
  374. sched_param :: struct {
  375. sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
  376. }
  377. } else when ODIN_OS == .OpenBSD {
  378. PTHREAD_CANCEL_ASYNCHRONOUS :: 2
  379. PTHREAD_CANCEL_DEFERRED :: 0
  380. PTHREAD_CANCEL_DISABLE :: 1
  381. PTHREAD_CANCEL_ENABLE :: 0
  382. PTHREAD_CANCELED :: rawptr(uintptr(1))
  383. PTHREAD_CREATE_DETACHED :: 0x1
  384. PTHREAD_CREATE_JOINABLE :: 0
  385. PTHREAD_EXPLICIT_SCHED :: 0
  386. PTHREAD_INHERIT_SCHED :: 0x4
  387. PTHREAD_PRIO_INHERIT :: 1
  388. PTHREAD_PRIO_NONE :: 0
  389. PTHREAD_PRIO_PROTECT :: 2
  390. PTHREAD_PROCESS_SHARED :: 0
  391. PTHREAD_PROCESS_PRIVATE :: 1
  392. PTHREAD_SCOPE_PROCESS :: 0
  393. PTHREAD_SCOPE_SYSTEM :: 0x2
  394. pthread_t :: distinct rawptr
  395. pthread_attr_t :: distinct rawptr
  396. pthread_key_t :: distinct c.int
  397. pthread_mutex_t :: distinct rawptr
  398. pthread_cond_t :: distinct rawptr
  399. sched_param :: struct {
  400. sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
  401. }
  402. } else when ODIN_OS == .Linux {
  403. PTHREAD_CANCEL_DEFERRED :: 0
  404. PTHREAD_CANCEL_ASYNCHRONOUS :: 1
  405. PTHREAD_CANCEL_ENABLE :: 0
  406. PTHREAD_CANCEL_DISABLE :: 1
  407. PTHREAD_CANCELED :: rawptr(~uintptr(0))
  408. PTHREAD_CREATE_JOINABLE :: 0
  409. PTHREAD_CREATE_DETACHED :: 1
  410. PTHREAD_INHERIT_SCHED :: 0
  411. PTHREAD_EXPLICIT_SCHED :: 1
  412. PTHREAD_PRIO_NONE :: 0
  413. PTHREAD_PRIO_INHERIT :: 1
  414. PTHREAD_PRIO_PROTECT :: 2
  415. PTHREAD_PROCESS_PRIVATE :: 0
  416. PTHREAD_PROCESS_SHARED :: 1
  417. PTHREAD_SCOPE_SYSTEM :: 0
  418. PTHREAD_SCOPE_PROCESS :: 1
  419. pthread_t :: distinct c.ulong
  420. pthread_attr_t :: struct #raw_union {
  421. __size: [56]c.char, // NOTE: may be smaller depending on libc or arch, but never larger.
  422. __align: c.long,
  423. }
  424. pthread_key_t :: distinct c.uint
  425. pthread_cond_t :: struct {
  426. __size: [40]c.char, // NOTE: may be smaller depending on libc or arch, but never larger.
  427. __align: c.long,
  428. }
  429. pthread_mutex_t :: struct {
  430. __size: [32]c.char, // NOTE: may be smaller depending on libc or arch, but never larger.
  431. __align: c.long,
  432. }
  433. sched_param :: struct {
  434. sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
  435. // NOTE: may be smaller depending on libc or arch, but never larger.
  436. __reserved1: c.int,
  437. __reserved2: [4]c.long,
  438. __reserved3: c.int,
  439. }
  440. }