12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #ifndef WIN32
- #include <pthread.h>
- #define THREAD_HANDLE pthread_t
- #define THREAD_CREATE(handle, callback) pthread_create(&handle, NULL, callback, NULL)
- #define THREAD_JOIN(handle) pthread_join(handle, NULL)
- #define THREAD_CALLBACK(name) static void * name(void *_)
- #else
- #include <windows.h>
- #define THREAD_HANDLE HANDLE
- #define THREAD_CREATE(handle, callback) { handle = CreateThread( NULL, 0, callback, NULL, 0, NULL); }
- #define THREAD_JOIN(handle) WaitForSingleObject(handle, INFINITE)
- #define THREAD_CALLBACK(name) static DWORD WINAPI name( LPVOID lpParam )
- #endif
- #ifndef WIN32
- #define MUTEX_HANDLE pthread_mutex_t
- #define MUTEX_INIT(name) (pthread_mutex_init(&(name), NULL) == 0)
- #define MUTEX_LOCK(name) (pthread_mutex_lock(&(name)) == 0)
- #define MUTEX_UNLOCK(name) (pthread_mutex_unlock(&(name)) == 0)
- #define MUTEX_DESTROY(name) (pthread_mutex_destroy(&(name)) == 0)
- #else
- #define MUTEX_HANDLE HANDLE
- #define MUTEX_INIT(name) (CreateMutex(NULL, FALSE, NULL) != 0)
- #define MUTEX_LOCK(name) (WaitForSingleObject((name), INFINITE) != 0)
- #define MUTEX_UNLOCK(name) (ReleaseMutex((name)) != 0)
- #define MUTEX_DESTROY(name) (CloseHandle((name)) != 0)
- #endif
|