12#ifndef XTC_OS_THREAD_H
13#define XTC_OS_THREAD_H
15#include "xtc_export.h"
28# define XTC_THREAD_LOCAL __declspec(thread)
29#elif defined(__GNUC__) || defined(__clang__)
30# define XTC_THREAD_LOCAL __thread
32# define XTC_THREAD_LOCAL _Thread_local
54struct __os_mutex { _Alignas(
long long)
unsigned char storage[64]; };
55struct __os_rwlock { _Alignas(
long long)
unsigned char storage[256]; };
56struct __os_cond { _Alignas(
long long)
unsigned char storage[64]; };
57struct __os_sem { _Alignas(
long long)
unsigned char storage[64]; };
70#define XTC_OS_MUTEX_INIT { { 0 } }
71#define XTC_OS_RWLOCK_INIT { { 0 } }
78typedef unsigned long __os_tls_key_t;
80typedef void *(*__os_thread_fn)(
void *);
81typedef void (*__os_tls_dtor)(
void *);
93typedef void *__os_once_t;
94#define XTC_OS_ONCE_INIT NULL
97typedef pthread_once_t __os_once_t;
98#define XTC_OS_ONCE_INIT PTHREAD_ONCE_INIT
113XTC_API
int __os_thread_create(__os_thread_t *thr, __os_thread_fn fn,
void *arg);
121int __os_pthread_create_masked(pthread_t *out,
void *(*fn)(
void *),
123XTC_API
int __os_thread_join(__os_thread_t *thr,
void **retval);
124XTC_API
int __os_thread_detach(__os_thread_t *thr);
125XTC_API
int __os_thread_self(__os_thread_t *out);
126XTC_API
void __os_thread_yield(
void);
127XTC_API
int __os_thread_setname(
const char *name);
128XTC_API
void __os_thread_apply_default_qos(
void);
129XTC_API
int __os_thread_set_affinity(
int cpu);
139XTC_API
int __os_tls_create(__os_tls_key_t *key, __os_tls_dtor dtor);
140XTC_API
int __os_tls_destroy(__os_tls_key_t key);
141XTC_API
int __os_tls_set(__os_tls_key_t key,
void *value);
142XTC_API
void *__os_tls_get(__os_tls_key_t key);
157XTC_API
int __os_thread_atexit(
void (*fn)(
void *),
void *arg);
164XTC_API
int __os_call_once(__os_once_t *once,
void (*fn)(
void));
175XTC_API
int __os_mutex_init(__os_mutex_t *m);
176XTC_API
int __os_mutex_destroy(__os_mutex_t *m);
177XTC_API
int __os_mutex_lock(__os_mutex_t *m);
178XTC_API
int __os_mutex_trylock(__os_mutex_t *m);
179XTC_API
int __os_mutex_unlock(__os_mutex_t *m);
198XTC_API
int __os_rwlock_init(__os_rwlock_t *r);
199XTC_API
int __os_rwlock_destroy(__os_rwlock_t *r);
200XTC_API
int __os_rwlock_rdlock(__os_rwlock_t *r);
201XTC_API
int __os_rwlock_wrlock(__os_rwlock_t *r);
202XTC_API
int __os_rwlock_rdunlock(__os_rwlock_t *r);
203XTC_API
int __os_rwlock_wrunlock(__os_rwlock_t *r);
214XTC_API
int __os_cond_init(__os_cond_t *c);
215XTC_API
int __os_cond_destroy(__os_cond_t *c);
216XTC_API
int __os_cond_wait(__os_cond_t *c, __os_mutex_t *m);
217XTC_API
int __os_cond_signal(__os_cond_t *c);
218XTC_API
int __os_cond_broadcast(__os_cond_t *c);
229XTC_API
int __os_sem_init(__os_sem_t *s,
unsigned initial);
230XTC_API
int __os_sem_destroy(__os_sem_t *s);
231XTC_API
int __os_sem_post(__os_sem_t *s);
232XTC_API
int __os_sem_wait(__os_sem_t *s);
233XTC_API
int __os_sem_trywait(__os_sem_t *s);