apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yla...@apache.org
Subject svn commit: r1738819 - in /apr/apr/branches/1.5.x: include/arch/unix/apr_arch_proc_mutex.h locks/unix/proc_mutex.c
Date Tue, 12 Apr 2016 15:55:16 GMT
Author: ylavic
Date: Tue Apr 12 15:55:16 2016
New Revision: 1738819

URL: http://svn.apache.org/viewvc?rev=1738819&view=rev
Log:
apr_proc_mutex-unix: backport r1733775 from trunk (partially).
Includes some fixes to unix proc_mutexes contained in the above commit (including
follow up to r1738800), but without non-backportable (API) changes.

Modified:
    apr/apr/branches/1.5.x/include/arch/unix/apr_arch_proc_mutex.h
    apr/apr/branches/1.5.x/locks/unix/proc_mutex.c

Modified: apr/apr/branches/1.5.x/include/arch/unix/apr_arch_proc_mutex.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/include/arch/unix/apr_arch_proc_mutex.h?rev=1738819&r1=1738818&r2=1738819&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/include/arch/unix/apr_arch_proc_mutex.h (original)
+++ apr/apr/branches/1.5.x/include/arch/unix/apr_arch_proc_mutex.h Tue Apr 12 15:55:16 2016
@@ -104,6 +104,10 @@ struct apr_proc_mutex_t {
 #endif
 #if APR_HAS_PROC_PTHREAD_SERIALIZE
     pthread_mutex_t *pthread_interproc;
+    int pthread_refcounting;    /* Whether the native mutex is refcounted or
+                                 * apr_os_proc_mutex_put()ed, which makes
+                                 * refcounting impossible/undesirable.
+                                 */
 #endif
 };
 

Modified: apr/apr/branches/1.5.x/locks/unix/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/locks/unix/proc_mutex.c?rev=1738819&r1=1738818&r2=1738819&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/locks/unix/proc_mutex.c (original)
+++ apr/apr/branches/1.5.x/locks/unix/proc_mutex.c Tue Apr 12 15:55:16 2016
@@ -343,6 +343,23 @@ typedef struct {
 #define proc_pthread_mutex_refcount(m) \
     (((proc_pthread_mutex_t *)(m)->pthread_interproc)->refcount)
 
+static APR_INLINE int proc_pthread_mutex_inc(apr_proc_mutex_t *mutex)
+{
+    if (mutex->pthread_refcounting) {
+        apr_atomic_inc32(&proc_pthread_mutex_refcount(mutex));
+        return 1;
+    }
+    return 0;
+}
+
+static APR_INLINE int proc_pthread_mutex_dec(apr_proc_mutex_t *mutex)
+{
+    if (mutex->pthread_refcounting) {
+        return apr_atomic_dec32(&proc_pthread_mutex_refcount(mutex));
+    }
+    return 0;
+}
+
 static apr_status_t proc_pthread_mutex_unref(void *mutex_)
 {
     apr_proc_mutex_t *mutex=mutex_;
@@ -356,7 +373,7 @@ static apr_status_t proc_pthread_mutex_u
             return rv;
         }
     }
-    if (!apr_atomic_dec32(&proc_pthread_mutex_refcount(mutex))) {
+    if (!proc_pthread_mutex_dec(mutex)) {
         if ((rv = pthread_mutex_destroy(mutex->pthread_interproc))) {
 #ifdef HAVE_ZOS_PTHREADS
             rv = errno;
@@ -378,8 +395,7 @@ static apr_status_t proc_mutex_proc_pthr
             return rv;
         }
     }
-    if (munmap((caddr_t)mutex->pthread_interproc,
-               sizeof(proc_pthread_mutex_t))) {
+    if (munmap(mutex->pthread_interproc, sizeof(proc_pthread_mutex_t))) {
         return errno;
     }
     return APR_SUCCESS;
@@ -397,17 +413,17 @@ static apr_status_t proc_mutex_proc_pthr
         return errno;
     }
 
-    new_mutex->pthread_interproc = (pthread_mutex_t *)mmap(
-                                       (caddr_t) 0, 
-                                       sizeof(proc_pthread_mutex_t),
-                                       PROT_READ | PROT_WRITE, MAP_SHARED,
-                                       fd, 0); 
-    if (new_mutex->pthread_interproc == (pthread_mutex_t *) (caddr_t) -1) {
+    new_mutex->pthread_interproc = mmap(NULL, sizeof(proc_pthread_mutex_t),
+                                        PROT_READ | PROT_WRITE, MAP_SHARED,
+                                        fd, 0); 
+    if (new_mutex->pthread_interproc == MAP_FAILED) {
+        rv = errno;
         close(fd);
-        return errno;
+        return rv;
     }
     close(fd);
 
+    new_mutex->pthread_refcounting = 1;
     new_mutex->curr_locked = -1; /* until the mutex has been created */
 
     if ((rv = pthread_mutexattr_init(&mattr))) {
@@ -478,9 +494,10 @@ static apr_status_t proc_mutex_proc_pthr
                                                        const char *fname)
 {
     (*mutex)->curr_locked = 0;
-    apr_atomic_inc32(&proc_pthread_mutex_refcount(*mutex));
-    apr_pool_cleanup_register(pool, *mutex, proc_pthread_mutex_unref, 
-                              apr_pool_cleanup_null);
+    if (proc_pthread_mutex_inc(*mutex)) {
+        apr_pool_cleanup_register(pool, *mutex, proc_pthread_mutex_unref, 
+                                  apr_pool_cleanup_null);
+    }
     return APR_SUCCESS;
 }
 
@@ -495,7 +512,7 @@ static apr_status_t proc_mutex_proc_pthr
 #ifdef HAVE_PTHREAD_MUTEX_ROBUST
         /* Okay, our owner died.  Let's try to make it consistent again. */
         if (rv == EOWNERDEAD) {
-            apr_atomic_dec32(&proc_pthread_mutex_refcount(mutex));
+            proc_pthread_mutex_dec(mutex);
             pthread_mutex_consistent_np(mutex->pthread_interproc);
         }
         else
@@ -520,6 +537,7 @@ static apr_status_t proc_mutex_proc_pthr
 #ifdef HAVE_PTHREAD_MUTEX_ROBUST
         /* Okay, our owner died.  Let's try to make it consistent again. */
         if (rv == EOWNERDEAD) {
+            proc_pthread_mutex_dec(mutex);
             pthread_mutex_consistent_np(mutex->pthread_interproc);
         }
         else
@@ -527,7 +545,7 @@ static apr_status_t proc_mutex_proc_pthr
         return rv;
     }
     mutex->curr_locked = 1;
-    return rv;
+    return APR_SUCCESS;
 }
 
 static apr_status_t proc_mutex_proc_pthread_release(apr_proc_mutex_t *mutex)
@@ -734,8 +752,9 @@ static apr_status_t proc_mutex_flock_cre
  
     if (rv != APR_SUCCESS) {
         proc_mutex_flock_cleanup(new_mutex);
-        return errno;
+        return rv;
     }
+
     new_mutex->curr_locked = 0;
     apr_pool_cleanup_register(new_mutex->pool, (void *)new_mutex,
                               apr_proc_mutex_cleanup,
@@ -795,13 +814,13 @@ static apr_status_t proc_mutex_flock_chi
     apr_proc_mutex_t *new_mutex;
     int rv;
 
-    new_mutex = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
-
-    memcpy(new_mutex, *mutex, sizeof *new_mutex);
-    new_mutex->pool = pool;
     if (!fname) {
         fname = (*mutex)->fname;
     }
+
+    new_mutex = (apr_proc_mutex_t *)apr_pmemdup(pool, *mutex,
+                                                sizeof(apr_proc_mutex_t));
+    new_mutex->pool = pool;
     new_mutex->fname = apr_pstrdup(pool, fname);
     rv = apr_file_open(&new_mutex->interproc, new_mutex->fname,
                        APR_FOPEN_WRITE, 0, new_mutex->pool);



Mime
View raw message