github.com/gotranspile/cxgo@v0.3.8-0.20240118201721-29871598a6a2/libs/includes/pthread.h (about) 1 #include <time.h> 2 3 const _cxgo_go_int PTHREAD_MUTEX_RECURSIVE = 1; 4 5 typedef struct pthread_mutex_t pthread_mutex_t; 6 7 typedef struct pthread_attr_t {} pthread_attr_t; 8 9 typedef struct { 10 void (*Do)(void (*fnc)(void)); 11 } pthread_once_t; 12 #define PTHREAD_ONCE_INIT {0} 13 #define pthread_once(o,f) (o)->Do(f) 14 15 typedef struct { 16 pthread_mutex_t* L; 17 void (*Wait)(void); 18 void (*Signal)(void); 19 void (*Broadcast)(void); 20 } pthread_cond_t; 21 typedef struct {} pthread_condattr_t; 22 int pthread_cond_destroy(pthread_cond_t *cond); 23 int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t * attr); 24 #define pthread_cond_broadcast(c) (c)->Broadcast() 25 #define pthread_cond_signal(c) (c)->Signal() 26 #define PTHREAD_COND_INITIALIZER {0} 27 28 typedef struct {} pthread_mutex_t; 29 int pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, const struct timespec * abstime); 30 //int pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex); 31 #define pthread_cond_wait(c,m) {(c)->L = m; (c)->Wait();} 32 33 typedef struct{ 34 _cxgo_sint32 (*Join)(void **retval); 35 _cxgo_sint32 (*TimedJoinNP)(void **retval, const struct timespec *abstime); 36 } pthread_t_; 37 #define pthread_t pthread_t_* 38 39 _cxgo_sint32 pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); 40 41 typedef struct pthread_mutexattr_t { 42 _cxgo_sint32 (*Init)(void); 43 _cxgo_sint32 (*SetType)(_cxgo_sint32 type); 44 _cxgo_sint32 (*Destroy)(void); 45 } pthread_mutexattr_t; 46 #define pthread_mutexattr_init(attr) ((pthread_mutexattr_t*)attr)->Init() 47 #define pthread_mutexattr_settype(attr, type) ((pthread_mutexattr_t*)attr)->SetType(type) 48 #define pthread_mutexattr_destroy(attr) ((pthread_mutexattr_t*)attr)->Destroy() 49 50 typedef struct pthread_mutex_t { 51 _cxgo_sint32 (*Destroy)(void); 52 _cxgo_sint32 (*Init)(const pthread_mutexattr_t *restrict attr); 53 _cxgo_sint32 (*CLock)(void); 54 _cxgo_sint32 (*TryLock)(void); 55 _cxgo_sint32 (*CUnlock)(void); 56 _cxgo_sint32 (*TimedLock)(const struct timespec *restrict abstime); 57 } pthread_mutex_t; 58 #define pthread_mutex_destroy(mutex) ((pthread_mutex_t*)mutex)->Destroy() 59 #define pthread_mutex_init(mutex, attr) ((pthread_mutex_t*)mutex)->Init(attr) 60 #define pthread_mutex_lock(mutex) ((pthread_mutex_t*)mutex)->CLock() 61 #define pthread_mutex_trylock(mutex) ((pthread_mutex_t*)mutex)->TryLock() 62 #define pthread_mutex_unlock(mutex) ((pthread_mutex_t*)mutex)->CUnlock() 63 #define pthread_mutex_timedlock(mutex, abstime) ((pthread_mutex_t*)mutex)->TimedLock(abstime) 64 65 #define pthread_join(thread, retval) ((pthread_t_*)thread)->Join(retval) 66 #define pthread_timedjoin_np(thread, retval, abstime) ((pthread_t_*)thread)->TimedJoinNP(retval, abstime) 67 68 void pthread_exit(void *retval);