Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35185 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42068 invoked by uid 1010); 5 Feb 2008 13:50:58 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 42053 invoked from network); 5 Feb 2008 13:50:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2008 13:50:58 -0000 Authentication-Results: pb1.pair.com header.from=scottmac@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=scottmac@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 72.232.140.210 as permitted sender) X-PHP-List-Original-Sender: scottmac@php.net X-Host-Fingerprint: 72.232.140.210 midden.org.uk Received: from [72.232.140.210] ([72.232.140.210:46294] helo=lovelace.midden.org.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E9/6D-14268-0C968A74 for ; Tue, 05 Feb 2008 08:50:58 -0500 Received: from office.vbulletin.com ([217.155.246.60] helo=[10.0.0.116]) by lovelace.midden.org.uk with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1JMOCL-0006Cu-90 for internals@lists.php.net; Tue, 05 Feb 2008 13:50:53 +0000 Message-ID: <47A869B5.1000907@php.net> Date: Tue, 05 Feb 2008 13:50:45 +0000 User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: php-dev Content-Type: multipart/mixed; boundary="------------090009060107070105010204" Subject: TSRM mutex return value inconsitencies From: scottmac@php.net (Scott MacVicar) --------------090009060107070105010204 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------090009060107070105010204 Content-Type: text/plain; name="tsrm_mutext_consistency.patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="tsrm_mutext_consistency.patch.txt" 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) --------------090009060107070105010204--