From 7229397c0c70c686c4de3de894fa9c0c434730f3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 11 Aug 2017 21:47:31 -0700 Subject: [PATCH] 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread/pthread/SDL_sysmutex.c b/src/thread/pthread/SDL_sysmutex.c index 1e668d92ab338..72d3bf3b17b2f 100644 --- a/src/thread/pthread/SDL_sysmutex.c +++ b/src/thread/pthread/SDL_sysmutex.c @@ -134,7 +134,7 @@ SDL_TryLockMutex(SDL_mutex * mutex) We set the locking thread id after we obtain the lock so unlocks from other threads will fail. */ - if (pthread_mutex_lock(&mutex->id) == 0) { + if (pthread_mutex_trylock(&mutex->id) == 0) { mutex->owner = this_thread; mutex->recursive = 0; } else if (errno == EBUSY) {