Last active
August 29, 2015 13:57
-
-
Save cynthia/9683222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// POSIX pthread compatibility shim for Windows. | |
#ifdef _WIN32 | |
#include <Windows.h> | |
typedef HANDLE pthread_mutex_t; | |
static int pthread_mutex_init(pthread_mutex_t *mutex, void *unused) | |
{ | |
unused = NULL; | |
*mutex = CreateMutex(NULL, FALSE, NULL); | |
return *mutex == NULL ? -1 : 0; | |
} | |
static int pthread_mutex_destroy(pthread_mutex_t *mutex) | |
{ | |
return CloseHandle(*mutex) == 0 ? -1 : 0; | |
} | |
static int pthread_mutex_lock(pthread_mutex_t *mutex) | |
{ | |
return WaitForSingleObject(*mutex, INFINITE) == WAIT_OBJECT_0? 0 : -1; | |
} | |
static int pthread_mutex_unlock(pthread_mutex_t *mutex) | |
{ | |
return ReleaseMutex(*mutex) == 0 ? -1 : 0; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment