You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dean Gaudet <dg...@arctic.org> on 1997/11/20 18:21:25 UTC

[PATCH] pthread_mutex_* error handling

Igor Tatarinov pointed out that the pthread_mutex_* functions do not set
errno on error, they return the error directly.  The patch below is based
on one Igor sent me. 

Note the extra "int err" in the two critical functions, doing this is
faster than setting errno directly, since err can be in a register. 

Dean

Index: CHANGES
===================================================================
RCS file: /export/home/cvs/apachen/src/CHANGES,v
retrieving revision 1.516
diff -u -r1.516 CHANGES
--- CHANGES	1997/11/20 00:42:32	1.516
+++ CHANGES	1997/11/20 17:16:50
@@ -1,5 +1,8 @@
 Changes with Apache 1.3b4
 
+  *) The pthread_mutex_* functions return an error code, and don't
+     set errno.  [Igor Tatarinov <ta...@prairie.NoDak.edu>]
+
 Changes with Apache 1.3b3
 
   *) WIN32: Work around brain-damaged spawn calls that can't deal
Index: main/http_main.c
===================================================================
RCS file: /export/home/cvs/apachen/src/main/http_main.c,v
retrieving revision 1.252
diff -u -r1.252 http_main.c
--- http_main.c	1997/11/16 15:43:16	1.252
+++ http_main.c	1997/11/20 17:16:52
@@ -389,15 +389,16 @@
 	exit(1);
     }
     close(fd);
-    if (pthread_mutexattr_init(&mattr)) {
+    if ((errno = pthread_mutexattr_init(&mattr))) {
 	perror("pthread_mutexattr_init");
 	exit(1);
     }
-    if (pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED)) {
+    if ((errno = pthread_mutexattr_setpshared(&mattr,
+						PTHREAD_PROCESS_SHARED))) {
 	perror("pthread_mutexattr_setpshared");
 	exit(1);
     }
-    if (pthread_mutex_init(accept_mutex, &mattr)) {
+    if ((errno = pthread_mutex_init(accept_mutex, &mattr))) {
 	perror("pthread_mutex_init");
 	exit(1);
     }
@@ -410,11 +411,14 @@
 
 static void accept_mutex_on()
 {
+    int err;
+
     if (sigprocmask(SIG_BLOCK, &accept_block_mask, &accept_previous_mask)) {
 	perror("sigprocmask(SIG_BLOCK)");
 	exit (1);
     }
-    if (pthread_mutex_lock(accept_mutex)) {
+    if ((err = pthread_mutex_lock(accept_mutex))) {
+	errno = err;
 	perror("pthread_mutex_lock");
 	exit(1);
     }
@@ -423,7 +427,10 @@
 
 static void accept_mutex_off()
 {
-    if (pthread_mutex_unlock(accept_mutex)) {
+    int err;
+
+    if ((err = pthread_mutex_unlock(accept_mutex))) {
+	errno = err;
 	perror("pthread_mutex_unlock");
 	exit(1);
     }