[Commits] TryLockMutex: Fix error handling for TryLockMutex

CHerzig at Gauselmann.de CHerzig at Gauselmann.de
Thu Feb 15 04:22:27 PST 2018


# HG changeset patch
# User Christian Herzig <cherzig at gauselmann.de>
# Date 1518696774 -3600
#      Thu Feb 15 13:12:54 2018 +0100
# Node ID 67ecc35403437db4bd948025ab8e5e0faa107461
# Parent  b0e4f5085af4398f8e0ceec06e6d0fe035734007
TryLockMutex: Fix error handling for TryLockMutex

pthread_mutex_trylock() and by the way, pthread_mutex_lock() do not set 
errno.
Pthread-methods directly return error code as int. See related man-pages 
for
details.

diff -r b0e4f5085af4 -r 67ecc3540343 src/thread/pthread/SDL_sysmutex.c
--- a/src/thread/pthread/SDL_sysmutex.c Tue Feb 13 22:58:20 2018 -0800
+++ b/src/thread/pthread/SDL_sysmutex.c Thu Feb 15 13:12:54 2018 +0100
@@ -116,6 +116,7 @@
 SDL_TryLockMutex(SDL_mutex * mutex)
 {
     int retval;
+    int err;
 #if FAKE_RECURSIVE_MUTEX
     pthread_t this_thread;
 #endif
@@ -134,18 +135,20 @@
          We set the locking thread id after we obtain the lock
          so unlocks from other threads will fail.
          */
-        if (pthread_mutex_trylock(&mutex->id) == 0) {
+        err = pthread_mutex_trylock(&mutex->id);
+        if (err == 0) {
             mutex->owner = this_thread;
             mutex->recursive = 0;
-        } else if (errno == EBUSY) {
+        } else if (err == EBUSY) {
             retval = SDL_MUTEX_TIMEDOUT;
         } else {
             retval = SDL_SetError("pthread_mutex_trylock() failed");
         }
     }
 #else
-    if (pthread_mutex_trylock(&mutex->id) != 0) {
-        if (errno == EBUSY) {
+    err = pthread_mutex_trylock(&mutex->id);
+    if (err != 0) {
+        if (err == EBUSY) {
             retval = SDL_MUTEX_TIMEDOUT;
         } else {
             retval = SDL_SetError("pthread_mutex_trylock() failed");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/commits-libsdl.org/attachments/20180215/8a44d722/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SDL_sysmutex.c.patch
Type: application/octet-stream
Size: 1757 bytes
Desc: not available
URL: <http://lists.libsdl.org/pipermail/commits-libsdl.org/attachments/20180215/8a44d722/attachment.obj>


More information about the commits mailing list