diff --git a/include/config-win.h b/include/config-win.h index 279be7aa5e4..f0804a368bc 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -19,6 +19,9 @@ /* We have to do this define before including windows.h to get the AWE API functions */ #define _WIN32_WINNT 0x0500 +#else +/* Get NT 4.0 functions */ +#define _WIN32_WINNT 0x0400 #endif #if defined(_MSC_VER) && _MSC_VER >= 1400 diff --git a/mysys/my_winthread.c b/mysys/my_winthread.c index e9fface0521..e94369bec32 100644 --- a/mysys/my_winthread.c +++ b/mysys/my_winthread.c @@ -40,31 +40,29 @@ void win_pthread_init(void) pthread_mutex_init(&THR_LOCK_thread,MY_MUTEX_INIT_FAST); } + /** Adapter to @c pthread_mutex_trylock() @retval 0 Mutex was acquired @retval EBUSY Mutex was already locked by a thread - @retval EINVAL Mutex could not be acquired due to other error */ int win_pthread_mutex_trylock(pthread_mutex_t *mutex) { - switch (WaitForSingleObject(mutex, 0)) { - case WAIT_TIMEOUT: - return EBUSY; - - default: - case WAIT_FAILURE: - return EINVAL; - - case WAIT_OBJECT_0: - case WAIT_ABANDONED: /* The mutex was acquired because it was - * abandoned */ + if (TryEnterCriticalSection(mutex)) + { + /* Don't allow recursive lock */ + if (mutex->RecursionCount > 1){ + LeaveCriticalSection(mutex); + return EBUSY; + } return 0; } + return EBUSY; } + /* ** We have tried to use '_beginthreadex' instead of '_beginthread' here ** but in this case the program leaks about 512 characters for each