Favor the Windows API over pthreads on mingw

This commit is contained in:
Frank Denis 2017-01-26 20:34:46 +01:00
parent 865a4a48ca
commit 8439df646b

View File

@ -1,10 +1,10 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#ifdef HAVE_PTHREAD #ifdef _WIN32
# include <pthread.h>
#elif defined(_WIN32)
# include <windows.h> # include <windows.h>
#elif defined(HAVE_PTHREAD)
# include <pthread.h>
#endif #endif
#include "core.h" #include "core.h"
@ -62,23 +62,7 @@ sodium_init(void)
return 0; return 0;
} }
#if defined(HAVE_PTHREAD) && !defined(__EMSCRIPTEN__) #ifdef _WIN32
static pthread_mutex_t _sodium_lock = PTHREAD_MUTEX_INITIALIZER;
int
sodium_crit_enter(void)
{
return pthread_mutex_lock(&_sodium_lock);
}
int
sodium_crit_leave(void)
{
return pthread_mutex_unlock(&_sodium_lock);
}
#elif defined(_WIN32)
static CRITICAL_SECTION _sodium_lock; static CRITICAL_SECTION _sodium_lock;
static volatile LONG _sodium_lock_initialized; static volatile LONG _sodium_lock_initialized;
@ -123,6 +107,22 @@ sodium_crit_leave(void)
return 0; return 0;
} }
#elif defined(HAVE_PTHREAD) && !defined(__EMSCRIPTEN__)
static pthread_mutex_t _sodium_lock = PTHREAD_MUTEX_INITIALIZER;
int
sodium_crit_enter(void)
{
return pthread_mutex_lock(&_sodium_lock);
}
int
sodium_crit_leave(void)
{
return pthread_mutex_unlock(&_sodium_lock);
}
#elif defined(HAVE_ATOMIC_OPS) && !defined(__EMSCRIPTEN__) && !defined(__native_client__) #elif defined(HAVE_ATOMIC_OPS) && !defined(__EMSCRIPTEN__) && !defined(__native_client__)
static volatile int _sodium_lock; static volatile int _sodium_lock;