65#define LIME_RWLOCK_RDUNLOCK(lock_ptr) pthread_rwlock_unlock(lock_ptr)
66#define LIME_RWLOCK_WRUNLOCK(lock_ptr) pthread_rwlock_unlock(lock_ptr)
73typedef SRWLOCK pthread_rwlock_t;
81typedef SRWLOCK pthread_mutex_t;
82typedef HANDLE pthread_t;
83typedef int pthread_attr_t;
84typedef int pthread_rwlockattr_t;
85typedef int pthread_mutexattr_t;
87#define PTHREAD_CREATE_DETACHED 1
88#define PTHREAD_CREATE_JOINABLE 0
92#define PTHREAD_MUTEX_INITIALIZER SRWLOCK_INIT
93#define PTHREAD_RWLOCK_INITIALIZER SRWLOCK_INIT
96static __inline
int pthread_rwlock_init(pthread_rwlock_t *lock,
97 const pthread_rwlockattr_t *a) {
99 InitializeSRWLock(lock);
102static __inline
int pthread_rwlock_destroy(pthread_rwlock_t *lock) {
106static __inline
int pthread_rwlock_rdlock(pthread_rwlock_t *lock) {
107 AcquireSRWLockShared(lock);
110static __inline
int pthread_rwlock_wrlock(pthread_rwlock_t *lock) {
111 AcquireSRWLockExclusive(lock);
116#define LIME_RWLOCK_RDUNLOCK(lock_ptr) ReleaseSRWLockShared(lock_ptr)
117#define LIME_RWLOCK_WRUNLOCK(lock_ptr) ReleaseSRWLockExclusive(lock_ptr)
123static __inline
int pthread_rwlock_unlock(pthread_rwlock_t *lock) {
129 ReleaseSRWLockExclusive(lock);
134static __inline
int pthread_mutex_init(pthread_mutex_t *m,
135 const pthread_mutexattr_t *a) {
137 InitializeSRWLock(m);
140static __inline
int pthread_mutex_destroy(pthread_mutex_t *m) {
144static __inline
int pthread_mutex_lock(pthread_mutex_t *m) {
145 AcquireSRWLockExclusive(m);
148static __inline
int pthread_mutex_unlock(pthread_mutex_t *m) {
149 ReleaseSRWLockExclusive(m);
160typedef CONDITION_VARIABLE pthread_cond_t;
161typedef int pthread_condattr_t;
163static __inline
int pthread_cond_init(pthread_cond_t *c,
164 const pthread_condattr_t *attr) {
166 InitializeConditionVariable(c);
169static __inline
int pthread_cond_destroy(pthread_cond_t *c) {
174static __inline
int pthread_cond_wait(pthread_cond_t *c,
175 pthread_mutex_t *m) {
179 SleepConditionVariableSRW(c, m, INFINITE, 0);
182static __inline
int pthread_cond_signal(pthread_cond_t *c) {
183 WakeConditionVariable(c);
186static __inline
int pthread_cond_broadcast(pthread_cond_t *c) {
187 WakeAllConditionVariable(c);
192static __inline
int pthread_attr_init(pthread_attr_t *a) {
193 *a = PTHREAD_CREATE_JOINABLE;
196static __inline
int pthread_attr_destroy(pthread_attr_t *a) {
200static __inline
int pthread_attr_setdetachstate(pthread_attr_t *a,
int s) {
204typedef unsigned (__stdcall *lime_thread_fn)(
void *);
205static __inline
int pthread_create(pthread_t *t,
206 const pthread_attr_t *attr,
207 void *(*start)(
void *),
215 HANDLE h = (HANDLE)_beginthreadex(NULL, 0,
216 (lime_thread_fn)(
void *)start,
218 if (h == NULL)
return 1;
220 if (attr != NULL && *attr == PTHREAD_CREATE_DETACHED) {
225static __inline
int pthread_detach(pthread_t t) {
229static __inline
int pthread_join(pthread_t t,
void **rv) {
230 WaitForSingleObject(t, INFINITE);
231 if (rv != NULL) *rv = NULL;