7 #define sleepms(x) Sleep(x)
9 typedef HANDLE thread_handle_t
;
11 #define THREAD_RETVAL DWORD WINAPI
12 #define THREAD_CREATE(handle, func, arg) \
13 handle = CreateThread(NULL, 0, func, arg, 0, NULL)
14 #define THREAD_JOIN(handle) do { WaitForSingleObject(handle, INFINITE); CloseHandle(handle); } while(0)
16 typedef HANDLE mutex_handle_t
;
18 #define MUTEX_CREATE(handle) handle = CreateMutex(NULL, FALSE, NULL)
19 #define MUTEX_LOCK(handle) WaitForSingleObject(handle, INFINITE)
20 #define MUTEX_UNLOCK(handle) ReleaseMutex(handle)
21 #define MUTEX_DESTROY(handle) CloseHandle(handle)
23 #else /* Use pthread library */
28 #define sleepms(x) usleep((x)*1000)
30 typedef pthread_t thread_handle_t
;
32 #define THREAD_RETVAL void *
33 #define THREAD_CREATE(handle, func, arg) \
34 if (pthread_create(&(handle), NULL, func, arg)) handle = 0
35 #define THREAD_JOIN(handle) pthread_join(handle, NULL)
37 typedef pthread_mutex_t mutex_handle_t
;
39 #define MUTEX_CREATE(handle) pthread_mutex_init(&(handle), NULL)
40 #define MUTEX_LOCK(handle) pthread_mutex_lock(&(handle))
41 #define MUTEX_UNLOCK(handle) pthread_mutex_unlock(&(handle))
42 #define MUTEX_DESTROY(handle) pthread_mutex_destroy(&(handle))
46 #endif /* THREADS_H */