1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
|
#+build linux, darwin, netbsd, openbsd, freebsd, haiku
package posix
import "core:c"
when ODIN_OS == .Darwin {
foreign import lib "system:System"
} else when ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .Linux {
foreign import lib "system:pthread"
} else {
foreign import lib "system:c"
}
// pthread.h - threads
// NOTE: mutexes, rwlock, condition variables, once and barriers are left out in favour of `core:sync`.
foreign lib {
/*
Initializes a thread attributes object.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_init.html ]]
*/
pthread_attr_init :: proc(attr: ^pthread_attr_t) -> Errno ---
/*
Destroys a thread attributes object.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_init.html ]]
*/
pthread_attr_destroy :: proc(attr: ^pthread_attr_t) -> Errno ---
/*
The detachstate attribute controls whether the thread is created in a detached state.
If the thread is created detached, then use of the ID of the newly created thread is an error.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getdetachstate.html ]]
*/
pthread_attr_getdetachstate :: proc(attr: ^pthread_attr_t, detachstate: ^Detach_State) -> Errno ---
/*
The detachstate attribute controls whether the thread is created in a detached state.
If the thread is created detached, then use of the ID of the newly created thread is an error.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getdetachstate.html ]]
*/
pthread_attr_setdetachstate :: proc(attr: ^pthread_attr_t, detachstate: Detach_State) -> Errno ---
/*
The guardsize attribute controls the size of the guard area for the created thread's stack.
The guardsize attribute provides protection against overflow of the stack pointer.
If a thread's stack is created with guard protection, the implementation allocates extra memory
at the overflow end of the stack as a buffer against stack overflow of the stack pointer.
If an application overflows into this buffer an error shall result (possibly in a SIGSEGV signal being delivered to the thread).
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setguardsize.html ]]
*/
pthread_attr_getguardsize :: proc(attr: ^pthread_attr_t, guardsize: ^c.size_t) -> Errno ---
/*
The guardsize attribute controls the size of the guard area for the created thread's stack.
The guardsize attribute provides protection against overflow of the stack pointer.
If a thread's stack is created with guard protection, the implementation allocates extra memory
at the overflow end of the stack as a buffer against stack overflow of the stack pointer.
If an application overflows into this buffer an error shall result (possibly in a SIGSEGV signal being delivered to the thread).
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setguardsize.html ]]
*/
pthread_attr_setguardsize :: proc(attr: ^pthread_attr_t, guardsize: c.size_t) -> Errno ---
/*
When the attributes objects are used by pthread_create(), the inheritsched attribute determines
how the other scheduling attributes of the created thread shall be set.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setinheritsched.html ]]
*/
pthread_attr_getinheritsched :: proc(attr: ^pthread_attr_t, inheritsched: ^Inherit_Sched) -> Errno ---
/*
When the attributes objects are used by pthread_create(), the inheritsched attribute determines
how the other scheduling attributes of the created thread shall be set.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setinheritsched.html ]]
*/
pthread_attr_setinheritsched :: proc(attr: ^pthread_attr_t, inheritsched: Inherit_Sched) -> Errno ---
/*
Gets the scheduling param.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedparam.html ]]
*/
pthread_attr_getschedparam :: proc(attr: ^pthread_attr_t, param: ^sched_param) -> Errno ---
/*
Sets the scheduling param.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedparam.html ]]
*/
pthread_attr_setschedparam :: proc(attr: ^pthread_attr_t, param: ^sched_param) -> Errno ---
/*
Gets the scheduling poicy.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getschedpolicy.html ]]
*/
pthread_attr_getschedpolicy :: proc(attr: ^pthread_attr_t, policy: ^Sched_Policy) -> Errno ---
/*
Sets the scheduling poicy.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getschedpolicy.html ]]
*/
pthread_attr_setschedpolicy :: proc(attr: ^pthread_attr_t, policy: Sched_Policy) -> Errno ---
/*
Gets the contention scope.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getscope.html ]]
*/
pthread_attr_getscope :: proc(attr: ^pthread_attr_t, contentionscope: ^Thread_Scope) -> Errno ---
/*
Sets the contention scope.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getscope.html ]]
*/
pthread_attr_setscope :: proc(attr: ^pthread_attr_t, contentionscope: Thread_Scope) -> Errno ---
/*
Get the area of storage to be used for the created thread's stack.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstack.html ]]
*/
pthread_attr_getstack :: proc(attr: ^pthread_attr_t, stackaddr: ^[^]byte, stacksize: ^c.size_t) -> Errno ---
/*
Specify the area of storage to be used for the created thread's stack.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstack.html ]]
*/
pthread_attr_setstack :: proc(attr: ^pthread_attr_t, stackaddr: [^]byte, stacksize: c.size_t) -> Errno ---
/*
Gets the stack size.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstacksize.html ]]
*/
pthread_attr_getstacksize :: proc(attr: ^pthread_attr_t, stacksize: ^c.size_t) -> Errno ---
/*
Sets the stack size.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstacksize.html ]]
*/
pthread_attr_setstacksize :: proc(attr: ^pthread_attr_t, stacksize: c.size_t) -> Errno ---
/*
Register fork handlers to be called before and after fork().
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_atfork.html ]]
*/
pthread_atfork :: proc(prepare: proc "c" (), parent: proc "c" (), child: proc "c" ()) -> Errno ---
/*
Cancel the execution of a thread.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cancel.html ]]
*/
pthread_cancel :: proc(thread: pthread_t) -> Errno ---
/*
Creates a new thread with the given attributes.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html ]]
*/
pthread_create :: proc(
thread: ^pthread_t,
attr: ^pthread_attr_t,
start_routine: proc "c" (arg: rawptr) -> rawptr,
arg: rawptr,
) -> Errno ---
/*
Indicate that storage for the thread can be reclaimed when the thread terminates.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_detach.html ]]
*/
pthread_detach :: proc(thread: pthread_t) -> Errno ---
/*
Compare thread IDs.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_equal.html ]]
*/
pthread_equal :: proc(t1: pthread_t, t2: pthread_t) -> b32 ---
/*
Terminates the calling thread and make the given value available to any successfull join calls.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_exit.html ]]
*/
pthread_exit :: proc(value_ptr: rawptr) -> ! ---
/*
Gets the current concurrency hint.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getconcurrency.html ]]
*/
pthread_getconcurrency :: proc() -> c.int ---
/*
Sets the current desired concurrency hint.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getconcurrency.html ]]
*/
pthread_setconcurrency :: proc(new_level: c.int) -> Errno ---
/*
Access a thread CPU-time clock.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getcpuclockid.html ]]
*/
pthread_getcpuclockid :: proc(thread_id: pthread_t, clock_id: ^clockid_t) -> Errno ---
/*
Gets the scheduling policy and parameters.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getschedparam.html ]]
*/
pthread_getschedparam :: proc(thread: pthread_t, policy: ^Sched_Policy, param: ^sched_param) -> Errno ---
/*
Sets the scheduling policy and parameters.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getschedparam.html ]]
*/
pthread_setschedparam :: proc(thread: pthread_t, policy: Sched_Policy, param: ^sched_param) -> Errno ---
/*
Creates a thread-specific data key visible to all threads in the process.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_key_create.html ]]
*/
pthread_key_create :: proc(key: ^pthread_key_t, destructor: proc "c" (value: rawptr) = nil) -> Errno ---
/*
Deletes a thread-specific data key visible to all threads in the process.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_key_delete.html ]]
*/
pthread_key_delete :: proc(key: pthread_key_t) -> Errno ---
/*
Returns the value currently bound to the specified key on behalf of the calling thread.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getspecific.html ]]
*/
pthread_getspecific :: proc(key: pthread_key_t) -> rawptr ---
/*
Sets the value currently bound to the specified key on behalf of the calling thread.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getspecific.html ]]
*/
pthread_setspecific :: proc(key: pthread_key_t, value: rawptr) -> Errno ---
/*
Suspends execution of the calling thread until the target thread terminates.
Example:
ar: [10_000]i32
sb1 := ar[:5_000]
sb2 := ar[5_000:]
th1, th2: posix.pthread_t
posix.pthread_create(&th1, nil, incer, &sb1)
posix.pthread_create(&th2, nil, incer, &sb2)
posix.pthread_join(th1)
posix.pthread_join(th2)
incer :: proc "c" (arg: rawptr) -> rawptr {
sb := (^[]i32)(arg)
for &val in sb {
val += 1
}
return nil
}
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html ]]
*/
pthread_join :: proc(thread: pthread_t, value_ptr: ^rawptr = nil) -> Errno ---
/*
Get the calling thread ID.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html ]]
*/
pthread_self :: proc() -> pthread_t ---
/*
Atomically set the calling thread's cancelability and return the previous value.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_setcancelstate.html ]]
*/
pthread_setcancelstate :: proc(state: Cancel_State, oldstate: ^Cancel_State) -> Errno ---
/*
Atomically set the calling thread's cancel type and return the previous value.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_setcancelstate.html ]]
*/
pthread_setcanceltype :: proc(type: Cancel_Type, oldtype: ^Cancel_Type) -> Errno ---
/*
Creates a cancellation point in the calling thread.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_testcancel.html ]]
*/
pthread_testcancel :: proc() ---
/*
Sets the scheduling priority for the thread given.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_setschedprio.html ]]
*/
pthread_setschedprio :: proc(thread: pthread_t, prio: c.int) -> Errno ---
}
Detach_State :: enum c.int {
// Causes all threads to be in the joinable state.
CREATE_JOINABLE = PTHREAD_CREATE_JOINABLE,
// Causes all threads to be in the detached state.
CREATE_DETACHED = PTHREAD_CREATE_DETACHED,
}
Inherit_Sched :: enum c.int {
// Threads inherit from the creating thread.
INHERIT_SCHED = PTHREAD_INHERIT_SCHED,
// Threads scheduling shall be set to the corresponding values from the attributes object.
EXPLICIT_SCHED = PTHREAD_EXPLICIT_SCHED,
}
Thread_Scope :: enum c.int {
// System scheduling contention scope.
SYSTEM = PTHREAD_SCOPE_SYSTEM,
// Process scheduling contention scope.
PROCESS = PTHREAD_SCOPE_PROCESS,
}
Cancel_State :: enum c.int {
// Cancel takes place at next cancellation point.
ENABLE = PTHREAD_CANCEL_ENABLE,
// Cancel postponed.
DISABLE = PTHREAD_CANCEL_DISABLE,
}
Cancel_Type :: enum c.int {
// Cancel waits until cancellation point.
DEFERRED = PTHREAD_CANCEL_DEFERRED,
// Cancel occurs immediately.
ASYNCHRONOUS = PTHREAD_CANCEL_ASYNCHRONOUS,
}
when ODIN_OS == .Darwin {
PTHREAD_CANCEL_ASYNCHRONOUS :: 0x00
PTHREAD_CANCEL_DEFERRED :: 0x02
PTHREAD_CANCEL_DISABLE :: 0x00
PTHREAD_CANCEL_ENABLE :: 0x01
// PTHREAD_CANCEL_ASYNCHRONOUS :: 1
// PTHREAD_CANCEL_DEFERRED :: 0
//
// PTHREAD_CANCEL_DISABLE :: 1
// PTHREAD_CANCEL_ENABLE :: 0
PTHREAD_CANCELED :: rawptr(uintptr(1))
PTHREAD_CREATE_DETACHED :: 2
PTHREAD_CREATE_JOINABLE :: 1
PTHREAD_EXPLICIT_SCHED :: 2
PTHREAD_INHERIT_SCHED :: 1
PTHREAD_PRIO_INHERIT :: 1
PTHREAD_PRIO_NONE :: 0
PTHREAD_PRIO_PROTECT :: 2
PTHREAD_PROCESS_SHARED :: 1
PTHREAD_PROCESS_PRIVATE :: 2
PTHREAD_SCOPE_PROCESS :: 2
PTHREAD_SCOPE_SYSTEM :: 1
pthread_t :: distinct rawptr
pthread_attr_t :: struct {
__sig: c.long,
__opaque: [56]c.char,
}
pthread_key_t :: distinct c.ulong
pthread_mutex_t :: struct {
__sig: c.long,
__opaque: [56]c.char,
}
pthread_cond_t :: struct {
__sig: c.long,
__opaque: [40]c.char,
}
sched_param :: struct {
sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
_: [4]c.char,
}
} else when ODIN_OS == .FreeBSD {
PTHREAD_CANCEL_ASYNCHRONOUS :: 0x02
PTHREAD_CANCEL_DEFERRED :: 0x00
PTHREAD_CANCEL_DISABLE :: 0x01
PTHREAD_CANCEL_ENABLE :: 0x00
PTHREAD_CANCELED :: rawptr(uintptr(1))
PTHREAD_CREATE_DETACHED :: 1
PTHREAD_CREATE_JOINABLE :: 0
PTHREAD_EXPLICIT_SCHED :: 0
PTHREAD_INHERIT_SCHED :: 4
PTHREAD_PRIO_INHERIT :: 1
PTHREAD_PRIO_NONE :: 0
PTHREAD_PRIO_PROTECT :: 2
PTHREAD_PROCESS_SHARED :: 1
PTHREAD_PROCESS_PRIVATE :: 0
PTHREAD_SCOPE_PROCESS :: 0
PTHREAD_SCOPE_SYSTEM :: 2
pthread_t :: distinct u64
pthread_attr_t :: struct #align(8) {
_: [8]byte,
}
pthread_key_t :: distinct c.int
pthread_mutex_t :: struct #align(8) {
_: [8]byte,
}
pthread_cond_t :: struct #align(8) {
_: [8]byte,
}
sched_param :: struct {
sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
}
} else when ODIN_OS == .NetBSD {
PTHREAD_CANCEL_ASYNCHRONOUS :: 1
PTHREAD_CANCEL_DEFERRED :: 0
PTHREAD_CANCEL_DISABLE :: 1
PTHREAD_CANCEL_ENABLE :: 0
PTHREAD_CANCELED :: rawptr(uintptr(1))
PTHREAD_CREATE_DETACHED :: 1
PTHREAD_CREATE_JOINABLE :: 0
PTHREAD_EXPLICIT_SCHED :: 1
PTHREAD_INHERIT_SCHED :: 0
PTHREAD_PRIO_INHERIT :: 1
PTHREAD_PRIO_NONE :: 0
PTHREAD_PRIO_PROTECT :: 2
PTHREAD_PROCESS_SHARED :: 1
PTHREAD_PROCESS_PRIVATE :: 0
PTHREAD_SCOPE_PROCESS :: 0
PTHREAD_SCOPE_SYSTEM :: 1
pthread_t :: distinct rawptr
pthread_attr_t :: struct {
pta_magic: c.uint,
pta_flags: c.int,
pta_private: rawptr,
}
pthread_key_t :: distinct c.int
pthread_cond_t :: struct #align(8) {
_: [40]byte,
}
pthread_mutex_t :: struct #align(8) {
_: [48]byte,
}
sched_param :: struct {
sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
}
} else when ODIN_OS == .OpenBSD {
PTHREAD_CANCEL_ASYNCHRONOUS :: 2
PTHREAD_CANCEL_DEFERRED :: 0
PTHREAD_CANCEL_DISABLE :: 1
PTHREAD_CANCEL_ENABLE :: 0
PTHREAD_CANCELED :: rawptr(uintptr(1))
PTHREAD_CREATE_DETACHED :: 0x1
PTHREAD_CREATE_JOINABLE :: 0
PTHREAD_EXPLICIT_SCHED :: 0
PTHREAD_INHERIT_SCHED :: 0x4
PTHREAD_PRIO_INHERIT :: 1
PTHREAD_PRIO_NONE :: 0
PTHREAD_PRIO_PROTECT :: 2
PTHREAD_PROCESS_SHARED :: 0
PTHREAD_PROCESS_PRIVATE :: 1
PTHREAD_SCOPE_PROCESS :: 0
PTHREAD_SCOPE_SYSTEM :: 0x2
pthread_t :: distinct rawptr
pthread_attr_t :: distinct rawptr
pthread_key_t :: distinct c.int
pthread_mutex_t :: distinct rawptr
pthread_cond_t :: distinct rawptr
sched_param :: struct {
sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
}
} else when ODIN_OS == .Haiku {
PTHREAD_CANCEL_ASYNCHRONOUS :: 2
PTHREAD_CANCEL_DEFERRED :: 0
PTHREAD_CANCEL_DISABLE :: 1
PTHREAD_CANCEL_ENABLE :: 0
PTHREAD_CANCELED :: rawptr(uintptr(1))
PTHREAD_CREATE_DETACHED :: 0x1
PTHREAD_CREATE_JOINABLE :: 0
PTHREAD_EXPLICIT_SCHED :: 0
PTHREAD_INHERIT_SCHED :: 0x4
PTHREAD_PRIO_INHERIT :: 1
PTHREAD_PRIO_NONE :: 0
PTHREAD_PRIO_PROTECT :: 2
PTHREAD_PROCESS_SHARED :: 1
PTHREAD_PROCESS_PRIVATE :: 0
PTHREAD_SCOPE_PROCESS :: 0
PTHREAD_SCOPE_SYSTEM :: 0x2
pthread_t :: distinct rawptr
pthread_attr_t :: distinct rawptr
pthread_key_t :: distinct c.int
pthread_mutex_t :: struct {
flags: u32,
lock: i32,
unused: i32,
owner: i32,
owner_count: i32,
}
pthread_cond_t :: struct {
flags: u32,
unused: i32,
mutex: ^pthread_mutex_t,
waiter_count: i32,
lock: i32,
}
sched_param :: struct {
sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
}
} else when ODIN_OS == .Linux {
PTHREAD_CANCEL_DEFERRED :: 0
PTHREAD_CANCEL_ASYNCHRONOUS :: 1
PTHREAD_CANCEL_ENABLE :: 0
PTHREAD_CANCEL_DISABLE :: 1
PTHREAD_CANCELED :: rawptr(~uintptr(0))
PTHREAD_CREATE_JOINABLE :: 0
PTHREAD_CREATE_DETACHED :: 1
PTHREAD_INHERIT_SCHED :: 0
PTHREAD_EXPLICIT_SCHED :: 1
PTHREAD_PRIO_NONE :: 0
PTHREAD_PRIO_INHERIT :: 1
PTHREAD_PRIO_PROTECT :: 2
PTHREAD_PROCESS_PRIVATE :: 0
PTHREAD_PROCESS_SHARED :: 1
PTHREAD_SCOPE_SYSTEM :: 0
PTHREAD_SCOPE_PROCESS :: 1
pthread_t :: distinct c.ulong
when ODIN_ARCH == .arm64 {
@(private)
__SIZEOF_PTHREAD_ATTR_T :: 64
} else {
@(private)
__SIZEOF_PTHREAD_ATTR_T :: 56
}
pthread_attr_t :: struct #raw_union {
__size: [__SIZEOF_PTHREAD_ATTR_T]c.char,
__align: c.long,
}
pthread_key_t :: distinct c.uint
pthread_cond_t :: struct {
__size: [40]c.char, // NOTE: may be smaller depending on libc or arch, but never larger.
__align: c.long,
}
pthread_mutex_t :: struct {
__size: [32]c.char, // NOTE: may be smaller depending on libc or arch, but never larger.
__align: c.long,
}
sched_param :: struct {
sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
// NOTE: may be smaller depending on libc or arch, but never larger.
__reserved1: c.int,
__reserved2: [4]c.long,
__reserved3: c.int,
}
}
|