Hi,

While doing some threaded work I noticed that tsrm_mutex_lock and tsrm_mutex_unlock return different values for Windows and Linux (using pthread).

Attached is the patch to make everything more pthread like, it will return 0 for success and any other value is an error.

Windows, GNU Portable Threads and the NSAPI implementations were returning incorrect values.

Scott
Index: TSRM/TSRM.c
===================================================================
RCS file: /repository/TSRM/TSRM.c,v
retrieving revision 1.68.2.3.2.1.2.1
diff -u -r1.68.2.3.2.1.2.1 TSRM.c
--- TSRM/TSRM.c 31 Dec 2007 07:17:03 -0000      1.68.2.3.2.1.2.1
+++ TSRM/TSRM.c 5 Feb 2008 13:24:50 -0000
@@ -647,19 +647,26 @@
 }
 
 
-/* Lock a mutex */
+/*
+  Lock a mutex.
+  A return value of 0 indicates success
+*/
 TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
 {
        TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex locked thread: %ld", 
tsrm_thread_id()));
 #ifdef TSRM_WIN32
        EnterCriticalSection(mutexp);
-       return 1;
+       return 0;
 #elif defined(GNUPTH)
-       return pth_mutex_acquire(mutexp, 0, NULL);
+       if (pth_mutex_acquire(mutexp, 0, NULL)) {
+               return 0;
+       }
+       return -1;
 #elif defined(PTHREADS)
        return pthread_mutex_lock(mutexp);
 #elif defined(NSAPI)
-       return crit_enter(mutexp);
+       crit_enter(mutexp);
+       return 0;
 #elif defined(PI3WEB)
        return PISync_lock(mutexp);
 #elif defined(TSRM_ST)
@@ -672,19 +679,26 @@
 }
 
 
-/* Unlock a mutex */
+/*
+  Unlock a mutex.
+  A return value of 0 indicates success
+*/
 TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
 {
        TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex unlocked thread: %ld", 
tsrm_thread_id()));
 #ifdef TSRM_WIN32
        LeaveCriticalSection(mutexp);
-       return 1;
+       return 0;
 #elif defined(GNUPTH)
-       return pth_mutex_release(mutexp);
+       if (pth_mutex_release(mutexp)) {
+               return 0;
+       }
+       return -1;
 #elif defined(PTHREADS)
        return pthread_mutex_unlock(mutexp);
 #elif defined(NSAPI)
-       return crit_exit(mutexp);
+       crit_exit(mutexp);
+       return 0;
 #elif defined(PI3WEB)
        return PISync_unlock(mutexp);
 #elif defined(TSRM_ST)

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to