diff options
author | unknown <mats@kindahl-laptop.dnsalias.net> | 2007-10-01 15:11:15 +0200 |
---|---|---|
committer | unknown <mats@kindahl-laptop.dnsalias.net> | 2007-10-01 15:11:15 +0200 |
commit | 2b9b71d0e3044572bc289701ae2a4055640a2bbb (patch) | |
tree | 8145f55af895335622aacc139487da26095a18a8 /include | |
parent | c6e88899460bd3478761f37a873a822f379a170d (diff) | |
download | mariadb-git-2b9b71d0e3044572bc289701ae2a4055640a2bbb.tar.gz |
BUG#30992 (Wrong implementation of pthread_mutex_trylock()):
Adding support for correct handling of pthread_mutex_trylock() on Win32
systems as well as when using the safe mutexes.
include/my_pthread.h:
Adding win_pthread_mutex_trylock() function as wrapper function for
Windows implementation of pthread_mutex_trylock().
Adding flag to safe_mutex_lock() that is shall not abort if the mutex
is already locked and instead return EBUSY since this is the POSIX
behaviour.
mysys/my_winthread.c:
Added Win32 wrappper function to handle pthread_mutex_trylock().
mysys/thr_mutex.c:
Added parameter 'try_lock' to safe_mutex_lock() to allow it to do double-
duty as a pthread_mutex_trylock() in addition to working as
pthread_mutex_lock().
The code needs to return EBUSY instead of throwing an error in the event
that the mutex is re-locked (we do not have recursive mutexes), but it
also requires some special handling to avoid race conditions when
calling the real pthread_mutex_{lock,trylock}().
Diffstat (limited to 'include')
-rw-r--r-- | include/my_pthread.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/include/my_pthread.h b/include/my_pthread.h index d64b5348666..e28bb9df1f3 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -135,6 +135,7 @@ struct timespec { void win_pthread_init(void); int win_pthread_setspecific(void *A,void *B,uint length); +int win_pthread_mutex_trylock(pthread_mutex_t *mutex); int pthread_create(pthread_t *,pthread_attr_t *,pthread_handler,void *); int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr); int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); @@ -195,7 +196,7 @@ extern int pthread_mutex_destroy (pthread_mutex_t *); #else #define pthread_mutex_init(A,B) (InitializeCriticalSection(A),0) #define pthread_mutex_lock(A) (EnterCriticalSection(A),0) -#define pthread_mutex_trylock(A) (WaitForSingleObject((A), 0) == WAIT_TIMEOUT) +#define pthread_mutex_trylock(A) win_pthread_mutex_trylock((A)) #define pthread_mutex_unlock(A) LeaveCriticalSection(A) #define pthread_mutex_destroy(A) DeleteCriticalSection(A) #define my_pthread_setprio(A,B) SetThreadPriority(GetCurrentThread(), (B)) @@ -593,7 +594,7 @@ typedef struct st_safe_mutex_info_t int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr, const char *file, uint line); -int safe_mutex_lock(safe_mutex_t *mp,const char *file, uint line); +int safe_mutex_lock(safe_mutex_t *mp, my_bool try_lock, const char *file, uint line); int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line); int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line); int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file, @@ -616,12 +617,12 @@ void safe_mutex_end(FILE *file); #undef pthread_cond_timedwait #undef pthread_mutex_trylock #define pthread_mutex_init(A,B) safe_mutex_init((A),(B),__FILE__,__LINE__) -#define pthread_mutex_lock(A) safe_mutex_lock((A),__FILE__,__LINE__) +#define pthread_mutex_lock(A) safe_mutex_lock((A), FALSE, __FILE__, __LINE__) #define pthread_mutex_unlock(A) safe_mutex_unlock((A),__FILE__,__LINE__) #define pthread_mutex_destroy(A) safe_mutex_destroy((A),__FILE__,__LINE__) #define pthread_cond_wait(A,B) safe_cond_wait((A),(B),__FILE__,__LINE__) #define pthread_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__) -#define pthread_mutex_trylock(A) pthread_mutex_lock(A) +#define pthread_mutex_trylock(A) safe_mutex_lock((A), TRUE, __FILE__, __LINE__) #define pthread_mutex_t safe_mutex_t #define safe_mutex_assert_owner(mp) \ DBUG_ASSERT((mp)->count > 0 && \ |