Rename a file that had a confusing filename.
[deb_shairplay.git] / src / threads.h
1 #ifndef THREADS_H
2 #define THREADS_H
3
4 #if defined(WIN32)
5 #include <windows.h>
6
7 #define sleepms(x) Sleep(x)
8
9 typedef HANDLE thread_handle_t;
10
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)
15
16 typedef HANDLE mutex_handle_t;
17
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)
22
23 #else /* Use pthread library */
24
25 #include <pthread.h>
26 #include <unistd.h>
27
28 #define sleepms(x) usleep((x)*1000)
29
30 typedef pthread_t thread_handle_t;
31
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)
36
37 typedef pthread_mutex_t mutex_handle_t;
38
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))
43
44 #endif
45
46 #endif /* THREADS_H */