pthread_darwin.odin 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //+build darwin
  2. package unix
  3. import "core:c"
  4. // NOTE(tetra): No 32-bit Macs.
  5. // Source: _pthread_types.h on my Mac.
  6. PTHREAD_SIZE :: 8176
  7. PTHREAD_ATTR_SIZE :: 56
  8. PTHREAD_MUTEXATTR_SIZE :: 8
  9. PTHREAD_MUTEX_SIZE :: 56
  10. PTHREAD_CONDATTR_SIZE :: 8
  11. PTHREAD_COND_SIZE :: 40
  12. PTHREAD_ONCE_SIZE :: 8
  13. PTHREAD_RWLOCK_SIZE :: 192
  14. PTHREAD_RWLOCKATTR_SIZE :: 16
  15. pthread_t :: distinct u64
  16. pthread_attr_t :: struct {
  17. sig: c.long,
  18. _: [PTHREAD_ATTR_SIZE] c.char,
  19. }
  20. pthread_cond_t :: struct {
  21. sig: c.long,
  22. _: [PTHREAD_COND_SIZE] c.char,
  23. }
  24. pthread_condattr_t :: struct {
  25. sig: c.long,
  26. _: [PTHREAD_CONDATTR_SIZE] c.char,
  27. }
  28. pthread_mutex_t :: struct {
  29. sig: c.long,
  30. _: [PTHREAD_MUTEX_SIZE] c.char,
  31. }
  32. pthread_mutexattr_t :: struct {
  33. sig: c.long,
  34. _: [PTHREAD_MUTEXATTR_SIZE] c.char,
  35. }
  36. pthread_once_t :: struct {
  37. sig: c.long,
  38. _: [PTHREAD_ONCE_SIZE] c.char,
  39. }
  40. pthread_rwlock_t :: struct {
  41. sig: c.long,
  42. _: [PTHREAD_RWLOCK_SIZE] c.char,
  43. }
  44. pthread_rwlockattr_t :: struct {
  45. sig: c.long,
  46. _: [PTHREAD_RWLOCKATTR_SIZE] c.char,
  47. }
  48. SCHED_OTHER :: 1 // Avoid if you are writing portable software.
  49. SCHED_FIFO :: 4
  50. SCHED_RR :: 2 // Round robin.
  51. SCHED_PARAM_SIZE :: 4
  52. sched_param :: struct {
  53. sched_priority: c.int,
  54. _: [SCHED_PARAM_SIZE] c.char,
  55. }
  56. // Source: https://github.com/apple/darwin-libpthread/blob/03c4628c8940cca6fd6a82957f683af804f62e7f/pthread/pthread.h#L138
  57. PTHREAD_CREATE_JOINABLE :: 1
  58. PTHREAD_CREATE_DETACHED :: 2
  59. PTHREAD_INHERIT_SCHED :: 1
  60. PTHREAD_EXPLICIT_SCHED :: 2
  61. PTHREAD_PROCESS_SHARED :: 1
  62. PTHREAD_PROCESS_PRIVATE :: 2
  63. PTHREAD_MUTEX_NORMAL :: 0
  64. PTHREAD_MUTEX_RECURSIVE :: 1
  65. PTHREAD_MUTEX_ERRORCHECK :: 2
  66. PTHREAD_CANCEL_ENABLE :: 0
  67. PTHREAD_CANCEL_DISABLE :: 1
  68. PTHREAD_CANCEL_DEFERRED :: 0
  69. PTHREAD_CANCEL_ASYNCHRONOUS :: 1
  70. foreign import pthread "system:System.framework"
  71. @(default_calling_convention="c")
  72. foreign pthread {
  73. pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
  74. pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
  75. pthread_cancel :: proc (thread: pthread_t) -> c.int ---
  76. }