mirror of
https://github.com/MariaDB/server.git
synced 2025-01-30 10:31:54 +01:00
Bug#30992 Wrong implementation of pthread_mutex_trylock()
It's not possible to use WaitForSingleObject to wait on a CRITICAL_SECTION, instead use the TryEnterCriticalSection function. - if "mutex" was already taken => return EBUSY - if "mutex" was aquired => return 0
This commit is contained in:
parent
23622616ab
commit
18c6118911
2 changed files with 13 additions and 12 deletions
|
@ -19,6 +19,9 @@
|
||||||
/* We have to do this define before including windows.h to get the AWE API
|
/* We have to do this define before including windows.h to get the AWE API
|
||||||
functions */
|
functions */
|
||||||
#define _WIN32_WINNT 0x0500
|
#define _WIN32_WINNT 0x0500
|
||||||
|
#else
|
||||||
|
/* Get NT 4.0 functions */
|
||||||
|
#define _WIN32_WINNT 0x0400
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
|
|
|
@ -40,31 +40,29 @@ void win_pthread_init(void)
|
||||||
pthread_mutex_init(&THR_LOCK_thread,MY_MUTEX_INIT_FAST);
|
pthread_mutex_init(&THR_LOCK_thread,MY_MUTEX_INIT_FAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Adapter to @c pthread_mutex_trylock()
|
Adapter to @c pthread_mutex_trylock()
|
||||||
|
|
||||||
@retval 0 Mutex was acquired
|
@retval 0 Mutex was acquired
|
||||||
@retval EBUSY Mutex was already locked by a thread
|
@retval EBUSY Mutex was already locked by a thread
|
||||||
@retval EINVAL Mutex could not be acquired due to other error
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
win_pthread_mutex_trylock(pthread_mutex_t *mutex)
|
win_pthread_mutex_trylock(pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
switch (WaitForSingleObject(mutex, 0)) {
|
if (TryEnterCriticalSection(mutex))
|
||||||
case WAIT_TIMEOUT:
|
{
|
||||||
return EBUSY;
|
/* Don't allow recursive lock */
|
||||||
|
if (mutex->RecursionCount > 1){
|
||||||
default:
|
LeaveCriticalSection(mutex);
|
||||||
case WAIT_FAILURE:
|
return EBUSY;
|
||||||
return EINVAL;
|
}
|
||||||
|
|
||||||
case WAIT_OBJECT_0:
|
|
||||||
case WAIT_ABANDONED: /* The mutex was acquired because it was
|
|
||||||
* abandoned */
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
return EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** We have tried to use '_beginthreadex' instead of '_beginthread' here
|
** We have tried to use '_beginthreadex' instead of '_beginthread' here
|
||||||
** but in this case the program leaks about 512 characters for each
|
** but in this case the program leaks about 512 characters for each
|
||||||
|
|
Loading…
Add table
Reference in a new issue