mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-21 13:55:45 +00:00
remove pthread from sys/unix and use sys/posix where used
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
#+build darwin
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
// NOTE(tetra): No 32-bit Macs.
|
||||
// Source: _pthread_types.h on my Mac.
|
||||
PTHREAD_SIZE :: 8176
|
||||
PTHREAD_ATTR_SIZE :: 56
|
||||
PTHREAD_MUTEXATTR_SIZE :: 8
|
||||
PTHREAD_MUTEX_SIZE :: 56
|
||||
PTHREAD_CONDATTR_SIZE :: 8
|
||||
PTHREAD_COND_SIZE :: 40
|
||||
PTHREAD_ONCE_SIZE :: 8
|
||||
PTHREAD_RWLOCK_SIZE :: 192
|
||||
PTHREAD_RWLOCKATTR_SIZE :: 16
|
||||
|
||||
pthread_t :: distinct u64
|
||||
|
||||
pthread_attr_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_ATTR_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_cond_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_COND_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_condattr_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_CONDATTR_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_mutex_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_MUTEX_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_mutexattr_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_MUTEXATTR_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_once_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_ONCE_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_rwlock_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_RWLOCK_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_rwlockattr_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_RWLOCKATTR_SIZE] c.char,
|
||||
}
|
||||
|
||||
SCHED_OTHER :: 1 // Avoid if you are writing portable software.
|
||||
SCHED_FIFO :: 4
|
||||
SCHED_RR :: 2 // Round robin.
|
||||
|
||||
SCHED_PARAM_SIZE :: 4
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
_: [SCHED_PARAM_SIZE] c.char,
|
||||
}
|
||||
|
||||
// Source: https://github.com/apple/darwin-libpthread/blob/03c4628c8940cca6fd6a82957f683af804f62e7f/pthread/pthread.h#L138
|
||||
PTHREAD_CREATE_JOINABLE :: 1
|
||||
PTHREAD_CREATE_DETACHED :: 2
|
||||
PTHREAD_INHERIT_SCHED :: 1
|
||||
PTHREAD_EXPLICIT_SCHED :: 2
|
||||
PTHREAD_PROCESS_SHARED :: 1
|
||||
PTHREAD_PROCESS_PRIVATE :: 2
|
||||
|
||||
|
||||
PTHREAD_MUTEX_NORMAL :: 0
|
||||
PTHREAD_MUTEX_RECURSIVE :: 1
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 2
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 1
|
||||
|
||||
foreign import pthread "system:System.framework"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
#+build freebsd
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
pthread_t :: distinct u64
|
||||
// pthread_t :: struct #align(16) { x: u64 }
|
||||
|
||||
PTHREAD_COND_T_SIZE :: 8
|
||||
|
||||
PTHREAD_MUTEXATTR_T_SIZE :: 8
|
||||
PTHREAD_CONDATTR_T_SIZE :: 8
|
||||
PTHREAD_RWLOCKATTR_T_SIZE :: 8
|
||||
PTHREAD_BARRIERATTR_T_SIZE :: 8
|
||||
|
||||
// WARNING: The sizes of these things are different yet again
|
||||
// on non-X86!
|
||||
when size_of(int) == 8 {
|
||||
PTHREAD_ATTR_T_SIZE :: 8
|
||||
PTHREAD_MUTEX_T_SIZE :: 8
|
||||
PTHREAD_RWLOCK_T_SIZE :: 8
|
||||
PTHREAD_BARRIER_T_SIZE :: 8
|
||||
} else when size_of(int) == 4 { // TODO
|
||||
PTHREAD_ATTR_T_SIZE :: 32
|
||||
PTHREAD_MUTEX_T_SIZE :: 32
|
||||
PTHREAD_RWLOCK_T_SIZE :: 44
|
||||
PTHREAD_BARRIER_T_SIZE :: 20
|
||||
}
|
||||
|
||||
pthread_cond_t :: struct #align(16) {
|
||||
_: [PTHREAD_COND_T_SIZE] c.char,
|
||||
}
|
||||
pthread_mutex_t :: struct #align(16) {
|
||||
_: [PTHREAD_MUTEX_T_SIZE] c.char,
|
||||
}
|
||||
pthread_rwlock_t :: struct #align(16) {
|
||||
_: [PTHREAD_RWLOCK_T_SIZE] c.char,
|
||||
}
|
||||
pthread_barrier_t :: struct #align(16) {
|
||||
_: [PTHREAD_BARRIER_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_attr_t :: struct #align(16) {
|
||||
_: [PTHREAD_ATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_condattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_CONDATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_mutexattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_MUTEXATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_rwlockattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_RWLOCKATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_barrierattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_BARRIERATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 1
|
||||
PTHREAD_MUTEX_RECURSIVE :: 2
|
||||
PTHREAD_MUTEX_NORMAL :: 3
|
||||
|
||||
|
||||
PTHREAD_CREATE_JOINABLE :: 0
|
||||
PTHREAD_CREATE_DETACHED :: 1
|
||||
PTHREAD_INHERIT_SCHED :: 4
|
||||
PTHREAD_EXPLICIT_SCHED :: 0
|
||||
PTHREAD_PROCESS_PRIVATE :: 0
|
||||
PTHREAD_PROCESS_SHARED :: 1
|
||||
|
||||
SCHED_FIFO :: 1
|
||||
SCHED_OTHER :: 2
|
||||
SCHED_RR :: 3 // Round robin.
|
||||
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
}
|
||||
|
||||
_usem :: struct {
|
||||
_has_waiters: u32,
|
||||
_count: u32,
|
||||
_flags: u32,
|
||||
}
|
||||
_usem2 :: struct {
|
||||
_count: u32,
|
||||
_flags: u32,
|
||||
}
|
||||
sem_t :: struct {
|
||||
_magic: u32,
|
||||
_kern: _usem2,
|
||||
_padding: u32,
|
||||
}
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 2
|
||||
|
||||
foreign import "system:pthread"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
// create named semaphore.
|
||||
// used in process-shared semaphores.
|
||||
sem_open :: proc(name: cstring, flags: c.int) -> ^sem_t ---
|
||||
|
||||
sem_init :: proc(sem: ^sem_t, pshared: c.int, initial_value: c.uint) -> c.int ---
|
||||
sem_destroy :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_post :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_wait :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_trywait :: proc(sem: ^sem_t) -> c.int ---
|
||||
// sem_timedwait :: proc(sem: ^sem_t, timeout: time.TimeSpec) -> c.int ---
|
||||
|
||||
// NOTE: unclear whether pthread_yield is well-supported on Linux systems,
|
||||
// see https://linux.die.net/man/3/pthread_yield
|
||||
pthread_yield :: proc() ---
|
||||
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
pthread_t :: distinct rawptr
|
||||
pthread_attr_t :: distinct rawptr
|
||||
pthread_mutex_t :: distinct rawptr
|
||||
pthread_mutexattr_t :: distinct rawptr
|
||||
pthread_cond_t :: distinct rawptr
|
||||
pthread_condattr_t :: distinct rawptr
|
||||
pthread_rwlock_t :: distinct rawptr
|
||||
pthread_rwlockattr_t :: distinct rawptr
|
||||
pthread_barrier_t :: distinct rawptr
|
||||
pthread_barrierattr_t :: distinct rawptr
|
||||
pthread_spinlock_t :: distinct rawptr
|
||||
|
||||
pthread_key_t :: distinct c.int
|
||||
pthread_once_t :: struct {
|
||||
state: c.int,
|
||||
mutex: pthread_mutex_t,
|
||||
}
|
||||
|
||||
PTHREAD_MUTEX_DEFAULT :: 0
|
||||
PTHREAD_MUTEX_NORMAL :: 1
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 2
|
||||
PTHREAD_MUTEX_RECURSIVE :: 3
|
||||
|
||||
PTHREAD_DETACHED :: 0x1
|
||||
PTHREAD_SCOPE_SYSTEM :: 0x2
|
||||
PTHREAD_INHERIT_SCHED :: 0x4
|
||||
PTHREAD_NOFLOAT :: 0x8
|
||||
|
||||
PTHREAD_CREATE_DETACHED :: PTHREAD_DETACHED
|
||||
PTHREAD_CREATE_JOINABLE :: 0
|
||||
PTHREAD_SCOPE_PROCESS :: 0
|
||||
PTHREAD_EXPLICIT_SCHED :: 0
|
||||
|
||||
SCHED_FIFO :: 1
|
||||
SCHED_RR :: 2
|
||||
SCHED_SPORADIC :: 3
|
||||
SCHED_OTHER :: 4
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
}
|
||||
|
||||
sem_t :: distinct rawptr
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 2
|
||||
|
||||
foreign import libc "system:c"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign libc {
|
||||
sem_open :: proc(name: cstring, flags: c.int) -> ^sem_t ---
|
||||
|
||||
sem_init :: proc(sem: ^sem_t, pshared: c.int, initial_value: c.uint) -> c.int ---
|
||||
sem_destroy :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_post :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_wait :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_trywait :: proc(sem: ^sem_t) -> c.int ---
|
||||
|
||||
pthread_yield :: proc() ---
|
||||
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
#+build linux
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
// TODO(tetra): For robustness, I'd like to mark this with align 16.
|
||||
// I cannot currently do this.
|
||||
// And at the time of writing there is a bug with putting it
|
||||
// as the only field in a struct.
|
||||
pthread_t :: distinct u64
|
||||
// pthread_t :: struct #align(16) { x: u64 };
|
||||
|
||||
// NOTE(tetra): Got all the size constants from pthreadtypes-arch.h on my
|
||||
// Linux machine.
|
||||
|
||||
PTHREAD_COND_T_SIZE :: 48
|
||||
|
||||
PTHREAD_MUTEXATTR_T_SIZE :: 4
|
||||
PTHREAD_CONDATTR_T_SIZE :: 4
|
||||
PTHREAD_RWLOCKATTR_T_SIZE :: 8
|
||||
PTHREAD_BARRIERATTR_T_SIZE :: 4
|
||||
|
||||
// WARNING: The sizes of these things are different yet again
|
||||
// on non-X86!
|
||||
when size_of(int) == 8 {
|
||||
PTHREAD_ATTR_T_SIZE :: 56
|
||||
PTHREAD_MUTEX_T_SIZE :: 40
|
||||
PTHREAD_RWLOCK_T_SIZE :: 56
|
||||
PTHREAD_BARRIER_T_SIZE :: 32
|
||||
} else when size_of(int) == 4 {
|
||||
PTHREAD_ATTR_T_SIZE :: 32
|
||||
PTHREAD_MUTEX_T_SIZE :: 32
|
||||
PTHREAD_RWLOCK_T_SIZE :: 44
|
||||
PTHREAD_BARRIER_T_SIZE :: 20
|
||||
}
|
||||
|
||||
pthread_cond_t :: struct #align(16) {
|
||||
_: [PTHREAD_COND_T_SIZE] c.char,
|
||||
}
|
||||
pthread_mutex_t :: struct #align(16) {
|
||||
_: [PTHREAD_MUTEX_T_SIZE] c.char,
|
||||
}
|
||||
pthread_rwlock_t :: struct #align(16) {
|
||||
_: [PTHREAD_RWLOCK_T_SIZE] c.char,
|
||||
}
|
||||
pthread_barrier_t :: struct #align(16) {
|
||||
_: [PTHREAD_BARRIER_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_attr_t :: struct #align(16) {
|
||||
_: [PTHREAD_ATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_condattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_CONDATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_mutexattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_MUTEXATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_rwlockattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_RWLOCKATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_barrierattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_BARRIERATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
PTHREAD_MUTEX_NORMAL :: 0
|
||||
PTHREAD_MUTEX_RECURSIVE :: 1
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 2
|
||||
|
||||
|
||||
// TODO(tetra, 2019-11-01): Maybe make `enum c.int`s for these?
|
||||
PTHREAD_CREATE_JOINABLE :: 0
|
||||
PTHREAD_CREATE_DETACHED :: 1
|
||||
PTHREAD_INHERIT_SCHED :: 0
|
||||
PTHREAD_EXPLICIT_SCHED :: 1
|
||||
PTHREAD_PROCESS_PRIVATE :: 0
|
||||
PTHREAD_PROCESS_SHARED :: 1
|
||||
|
||||
SCHED_OTHER :: 0
|
||||
SCHED_FIFO :: 1
|
||||
SCHED_RR :: 2 // Round robin.
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
}
|
||||
|
||||
sem_t :: struct #align(16) {
|
||||
_: [SEM_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
when size_of(int) == 8 {
|
||||
SEM_T_SIZE :: 32
|
||||
} else when size_of(int) == 4 {
|
||||
SEM_T_SIZE :: 16
|
||||
}
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 1
|
||||
|
||||
foreign import "system:pthread"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
// create named semaphore.
|
||||
// used in process-shared semaphores.
|
||||
sem_open :: proc(name: cstring, flags: c.int) -> ^sem_t ---
|
||||
|
||||
sem_init :: proc(sem: ^sem_t, pshared: c.int, initial_value: c.uint) -> c.int ---
|
||||
sem_destroy :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_post :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_wait :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_trywait :: proc(sem: ^sem_t) -> c.int ---
|
||||
// sem_timedwait :: proc(sem: ^sem_t, timeout: time.TimeSpec) -> c.int ---;
|
||||
|
||||
// NOTE: unclear whether pthread_yield is well-supported on Linux systems,
|
||||
// see https://linux.die.net/man/3/pthread_yield
|
||||
pthread_yield :: proc() -> c.int ---
|
||||
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
pthread_t :: distinct rawptr
|
||||
|
||||
SEM_T_SIZE :: 8
|
||||
|
||||
PTHREAD_CONDATTR_T_SIZE :: 16
|
||||
PTHREAD_MUTEXATTR_T_SIZE :: 16
|
||||
PTHREAD_RWLOCKATTR_T_SIZE :: 16
|
||||
PTHREAD_BARRIERATTR_T_SIZE :: 16
|
||||
|
||||
PTHREAD_COND_T_SIZE :: 40
|
||||
PTHREAD_MUTEX_T_SIZE :: 48
|
||||
PTHREAD_RWLOCK_T_SIZE :: 64
|
||||
PTHREAD_BARRIER_T_SIZE :: 48
|
||||
PTHREAD_ATTR_T_SIZE :: 16
|
||||
|
||||
pthread_cond_t :: struct #align(8) {
|
||||
_: [PTHREAD_COND_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_mutex_t :: struct #align(8) {
|
||||
_: [PTHREAD_MUTEX_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_rwlock_t :: struct #align(8) {
|
||||
_: [PTHREAD_RWLOCK_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_barrier_t :: struct #align(8) {
|
||||
_: [PTHREAD_BARRIER_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_attr_t :: struct #align(8) {
|
||||
_: [PTHREAD_ATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_condattr_t :: struct #align(8) {
|
||||
_: [PTHREAD_CONDATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_mutexattr_t :: struct #align(8) {
|
||||
_: [PTHREAD_MUTEXATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_rwlockattr_t :: struct #align(8) {
|
||||
_: [PTHREAD_RWLOCKATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_barrierattr_t :: struct #align(8) {
|
||||
_: [PTHREAD_BARRIERATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
PTHREAD_MUTEX_NORMAL :: 0
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 1
|
||||
PTHREAD_MUTEX_RECURSIVE :: 2
|
||||
|
||||
PTHREAD_CREATE_JOINABLE :: 0
|
||||
PTHREAD_CREATE_DETACHED :: 1
|
||||
PTHREAD_INHERIT_SCHED :: 0
|
||||
PTHREAD_EXPLICIT_SCHED :: 1
|
||||
PTHREAD_PROCESS_PRIVATE :: 0
|
||||
PTHREAD_PROCESS_SHARED :: 1
|
||||
|
||||
SCHED_NONE :: -1
|
||||
SCHED_OTHER :: 0
|
||||
SCHED_FIFO :: 1
|
||||
SCHED_RR :: 3
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
}
|
||||
|
||||
sem_t :: struct #align(16) {
|
||||
_: [SEM_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 1
|
||||
|
||||
foreign import "system:pthread"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
sem_open :: proc(name: cstring, flags: c.int) -> ^sem_t ---
|
||||
|
||||
sem_init :: proc(sem: ^sem_t, pshared: c.int, initial_value: c.uint) -> c.int ---
|
||||
sem_destroy :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_post :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_wait :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_trywait :: proc(sem: ^sem_t) -> c.int ---
|
||||
|
||||
pthread_yield :: proc() ---
|
||||
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
#+build openbsd
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
pthread_t :: distinct rawptr
|
||||
pthread_attr_t :: distinct rawptr
|
||||
pthread_mutex_t :: distinct rawptr
|
||||
pthread_mutexattr_t :: distinct rawptr
|
||||
pthread_cond_t :: distinct rawptr
|
||||
pthread_condattr_t :: distinct rawptr
|
||||
pthread_rwlock_t :: distinct rawptr
|
||||
pthread_rwlockattr_t :: distinct rawptr
|
||||
pthread_barrier_t :: distinct rawptr
|
||||
pthread_barrierattr_t :: distinct rawptr
|
||||
pthread_spinlock_t :: distinct rawptr
|
||||
|
||||
pthread_key_t :: distinct c.int
|
||||
pthread_once_t :: struct {
|
||||
state: c.int,
|
||||
mutex: pthread_mutex_t,
|
||||
}
|
||||
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 1
|
||||
PTHREAD_MUTEX_RECURSIVE :: 2
|
||||
PTHREAD_MUTEX_NORMAL :: 3
|
||||
PTHREAD_MUTEX_STRICT_NP :: 4
|
||||
|
||||
PTHREAD_DETACHED :: 0x1
|
||||
PTHREAD_SCOPE_SYSTEM :: 0x2
|
||||
PTHREAD_INHERIT_SCHED :: 0x4
|
||||
PTHREAD_NOFLOAT :: 0x8
|
||||
|
||||
PTHREAD_CREATE_DETACHED :: PTHREAD_DETACHED
|
||||
PTHREAD_CREATE_JOINABLE :: 0
|
||||
PTHREAD_SCOPE_PROCESS :: 0
|
||||
PTHREAD_EXPLICIT_SCHED :: 0
|
||||
|
||||
SCHED_FIFO :: 1
|
||||
SCHED_OTHER :: 2
|
||||
SCHED_RR :: 3
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
}
|
||||
|
||||
sem_t :: distinct rawptr
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 2
|
||||
|
||||
foreign import libc "system:c"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign libc {
|
||||
sem_open :: proc(name: cstring, flags: c.int) -> ^sem_t ---
|
||||
|
||||
sem_init :: proc(sem: ^sem_t, pshared: c.int, initial_value: c.uint) -> c.int ---
|
||||
sem_destroy :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_post :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_wait :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_trywait :: proc(sem: ^sem_t) -> c.int ---
|
||||
//sem_timedwait :: proc(sem: ^sem_t, timeout: time.TimeSpec) -> c.int ---
|
||||
|
||||
// NOTE: unclear whether pthread_yield is well-supported on Linux systems,
|
||||
// see https://linux.die.net/man/3/pthread_yield
|
||||
pthread_yield :: proc() ---
|
||||
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
#+build linux, darwin, freebsd, openbsd, netbsd, haiku
|
||||
package unix
|
||||
|
||||
foreign import "system:pthread"
|
||||
|
||||
import "core:c"
|
||||
|
||||
timespec :: struct {
|
||||
tv_sec: i64,
|
||||
tv_nsec: i64,
|
||||
}
|
||||
|
||||
//
|
||||
// On success, these functions return 0.
|
||||
//
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
pthread_create :: proc(t: ^pthread_t, attrs: ^pthread_attr_t, routine: proc(data: rawptr) -> rawptr, arg: rawptr) -> c.int ---
|
||||
|
||||
// retval is a pointer to a location to put the return value of the thread proc.
|
||||
pthread_join :: proc(t: pthread_t, retval: ^rawptr) -> c.int ---
|
||||
|
||||
pthread_kill :: proc(t: pthread_t, sig: c.int) -> c.int ---
|
||||
|
||||
pthread_self :: proc() -> pthread_t ---
|
||||
|
||||
pthread_equal :: proc(a, b: pthread_t) -> b32 ---
|
||||
|
||||
pthread_detach :: proc(t: pthread_t) -> c.int ---
|
||||
|
||||
sched_get_priority_min :: proc(policy: c.int) -> c.int ---
|
||||
sched_get_priority_max :: proc(policy: c.int) -> c.int ---
|
||||
|
||||
// NOTE: POSIX says this can fail with OOM.
|
||||
pthread_attr_init :: proc(attrs: ^pthread_attr_t) -> c.int ---
|
||||
|
||||
pthread_attr_destroy :: proc(attrs: ^pthread_attr_t) -> c.int ---
|
||||
|
||||
pthread_attr_getschedparam :: proc(attrs: ^pthread_attr_t, param: ^sched_param) -> c.int ---
|
||||
pthread_attr_setschedparam :: proc(attrs: ^pthread_attr_t, param: ^sched_param) -> c.int ---
|
||||
|
||||
// states: PTHREAD_CREATE_DETACHED, PTHREAD_CREATE_JOINABLE
|
||||
pthread_attr_setdetachstate :: proc(attrs: ^pthread_attr_t, detach_state: c.int) -> c.int ---
|
||||
|
||||
// NOTE(tetra, 2019-11-06): WARNING: Different systems have different alignment requirements.
|
||||
// For maximum usefulness, use the OS's page size.
|
||||
// ALSO VERY MAJOR WARNING: `stack_ptr` must be the LAST byte of the stack on systems
|
||||
// where the stack grows downwards, which is the common case, so far as I know.
|
||||
// On systems where it grows upwards, give the FIRST byte instead.
|
||||
// ALSO SLIGHTLY LESS MAJOR WARNING: Using this procedure DISABLES automatically-provided
|
||||
// guard pages. If you are using this procedure, YOU must set them up manually.
|
||||
// If you forget to do this, you WILL get stack corruption bugs if you do not EXTREMELY
|
||||
// know what you are doing!
|
||||
pthread_attr_setstack :: proc(attrs: ^pthread_attr_t, stack_ptr: rawptr, stack_size: u64) -> c.int ---
|
||||
pthread_attr_getstack :: proc(attrs: ^pthread_attr_t, stack_ptr: ^rawptr, stack_size: ^u64) -> c.int ---
|
||||
|
||||
pthread_sigmask :: proc(how: c.int, set: rawptr, oldset: rawptr) -> c.int ---
|
||||
|
||||
sched_yield :: proc() -> c.int ---
|
||||
}
|
||||
|
||||
// NOTE: Unimplemented in Haiku.
|
||||
when ODIN_OS != .Haiku {
|
||||
foreign pthread {
|
||||
// scheds: PTHREAD_INHERIT_SCHED, PTHREAD_EXPLICIT_SCHED
|
||||
pthread_attr_setinheritsched :: proc(attrs: ^pthread_attr_t, sched: c.int) -> c.int ---
|
||||
|
||||
pthread_attr_getschedpolicy :: proc(t: ^pthread_attr_t, policy: ^c.int) -> c.int ---
|
||||
pthread_attr_setschedpolicy :: proc(t: ^pthread_attr_t, policy: c.int) -> c.int ---
|
||||
}
|
||||
}
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
// NOTE: POSIX says this can fail with OOM.
|
||||
pthread_cond_init :: proc(cond: ^pthread_cond_t, attrs: ^pthread_condattr_t) -> c.int ---
|
||||
|
||||
pthread_cond_destroy :: proc(cond: ^pthread_cond_t) -> c.int ---
|
||||
|
||||
pthread_cond_signal :: proc(cond: ^pthread_cond_t) -> c.int ---
|
||||
|
||||
// same as signal, but wakes up _all_ threads that are waiting
|
||||
pthread_cond_broadcast :: proc(cond: ^pthread_cond_t) -> c.int ---
|
||||
|
||||
|
||||
// assumes the mutex is pre-locked
|
||||
pthread_cond_wait :: proc(cond: ^pthread_cond_t, mutex: ^pthread_mutex_t) -> c.int ---
|
||||
pthread_cond_timedwait :: proc(cond: ^pthread_cond_t, mutex: ^pthread_mutex_t, timeout: ^timespec) -> c.int ---
|
||||
|
||||
pthread_condattr_init :: proc(attrs: ^pthread_condattr_t) -> c.int ---
|
||||
pthread_condattr_destroy :: proc(attrs: ^pthread_condattr_t) -> c.int ---
|
||||
|
||||
// p-shared = "process-shared" - i.e: is this condition shared among multiple processes?
|
||||
// values: PTHREAD_PROCESS_PRIVATE, PTHREAD_PROCESS_SHARED
|
||||
pthread_condattr_setpshared :: proc(attrs: ^pthread_condattr_t, value: c.int) -> c.int ---
|
||||
pthread_condattr_getpshared :: proc(attrs: ^pthread_condattr_t, result: ^c.int) -> c.int ---
|
||||
|
||||
}
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
// NOTE: POSIX says this can fail with OOM.
|
||||
pthread_mutex_init :: proc(mutex: ^pthread_mutex_t, attrs: ^pthread_mutexattr_t) -> c.int ---
|
||||
|
||||
pthread_mutex_destroy :: proc(mutex: ^pthread_mutex_t) -> c.int ---
|
||||
|
||||
pthread_mutex_trylock :: proc(mutex: ^pthread_mutex_t) -> c.int ---
|
||||
|
||||
pthread_mutex_lock :: proc(mutex: ^pthread_mutex_t) -> c.int ---
|
||||
|
||||
pthread_mutex_timedlock :: proc(mutex: ^pthread_mutex_t, timeout: ^timespec) -> c.int ---
|
||||
|
||||
pthread_mutex_unlock :: proc(mutex: ^pthread_mutex_t) -> c.int ---
|
||||
|
||||
|
||||
pthread_mutexattr_init :: proc(attrs: ^pthread_mutexattr_t) -> c.int ---
|
||||
pthread_mutexattr_destroy :: proc(attrs: ^pthread_mutexattr_t) -> c.int ---
|
||||
pthread_mutexattr_settype :: proc(attrs: ^pthread_mutexattr_t, type: c.int) -> c.int ---
|
||||
|
||||
// p-shared = "process-shared" - i.e: is this mutex shared among multiple processes?
|
||||
// values: PTHREAD_PROCESS_PRIVATE, PTHREAD_PROCESS_SHARED
|
||||
pthread_mutexattr_setpshared :: proc(attrs: ^pthread_mutexattr_t, value: c.int) -> c.int ---
|
||||
pthread_mutexattr_getpshared :: proc(attrs: ^pthread_mutexattr_t, result: ^c.int) -> c.int ---
|
||||
|
||||
pthread_testcancel :: proc () ---
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package unix
|
||||
|
||||
import "core:sys/posix"
|
||||
|
||||
timespec :: posix.timespec
|
||||
Reference in New Issue
Block a user