Fixed bug 3258 - SDL_TryLockMutex blocks for pthreads with FAKE_RECURSIVE_MUTEX
authorSam Lantinga <slouken@libsdl.org>
Fri, 11 Aug 2017 21:47:31 -0700
changeset 11233554b2c683da2
parent 11232 b26929d6ca20
child 11234 b5cf1e85ffd5
Fixed bug 3258 - SDL_TryLockMutex blocks for pthreads with FAKE_RECURSIVE_MUTEX

Ian Abbott

I just spotted what I think is a bug in "src/thread/pthread/SDL_sysmutex.c" in the SDL_TryLockMutex function when FAKE_RECURSIVE_MUTEX is defined (for an implementation of Pthreads with no recursive mutex support). It calls pthread_mutex_lock instead of pthread_mutex_trylock, so it will block until the mutex is available instead of returning SDL_MUTEX_TIMEDOUT if it cannot lock the mutex immediately.
src/thread/pthread/SDL_sysmutex.c
     1.1 --- a/src/thread/pthread/SDL_sysmutex.c	Fri Aug 11 21:30:06 2017 -0700
     1.2 +++ b/src/thread/pthread/SDL_sysmutex.c	Fri Aug 11 21:47:31 2017 -0700
     1.3 @@ -134,7 +134,7 @@
     1.4           We set the locking thread id after we obtain the lock
     1.5           so unlocks from other threads will fail.
     1.6           */
     1.7 -        if (pthread_mutex_lock(&mutex->id) == 0) {
     1.8 +        if (pthread_mutex_trylock(&mutex->id) == 0) {
     1.9              mutex->owner = this_thread;
    1.10              mutex->recursive = 0;
    1.11          } else if (errno == EBUSY) {