You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2016/03/06 01:19:51 UTC

svn commit: r1733775 - in /apr/apr/trunk: ./ include/ include/arch/unix/ locks/beos/ locks/netware/ locks/os2/ locks/unix/ locks/win32/

Author: ylavic
Date: Sun Mar  6 00:19:51 2016
New Revision: 1733775

URL: http://svn.apache.org/viewvc?rev=1733775&view=rev
Log:
apr_proc/global_mutex: Fix API regarding the native OS mutexes
accessors from/to available APR mechanisms, adding the new functions
apr_os_proc_mutex_get_ex() and apr_os_proc_mutex_set_ex() which give
control to the user over the selected mechanisms, including the missing
POSIX semaphores (sem_t) on platforms supporting them.

For POSIX sems, this moves the "sem_t *psem_interproc;" member from struct
apr_proc_mutex_t to apr_os_proc_mutex_t (now complete) so that we can avoid
members duplication between the two structs, and hence replace all the doublons
in apr_os_proc_mutex_t with an apr_os_proc_mutex_t member, called "os", to be
used for runtime.

This first commit aims to be backportable to 1.6.x, thus does not address the
Netware case which requires an incompatible change of the apr_proc_mutex_t to
a pointer type (the implementation is here since very similar to other changes
is this commit, but it is commented out for now, a simple follow up is coming
with the type change for trunk only...).
 

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/include/apr_global_mutex.h
    apr/apr/trunk/include/apr_portable.h
    apr/apr/trunk/include/apr_proc_mutex.h
    apr/apr/trunk/include/arch/unix/apr_arch_proc_mutex.h
    apr/apr/trunk/locks/beos/proc_mutex.c
    apr/apr/trunk/locks/netware/proc_mutex.c
    apr/apr/trunk/locks/os2/proc_mutex.c
    apr/apr/trunk/locks/unix/global_mutex.c
    apr/apr/trunk/locks/unix/proc_mutex.c
    apr/apr/trunk/locks/win32/proc_mutex.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1733775&r1=1733774&r2=1733775&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Sun Mar  6 00:19:51 2016
@@ -1,6 +1,13 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) apr_proc/global_mutex: Fix API regarding the native OS mutexes
+     accessors from/to available APR mechanisms, adding the new functions
+     apr_os_proc_mutex_get_ex() and apr_os_proc_mutex_set_ex() which give
+     control to the user over the selected mechanisms, including the missing
+     POSIX semaphores (sem_t) on platforms supporting them.
+     [Yann Ylavic]
+
   *) apr_proc_mutex-pthread: Refcount shared mutexes usage to avoid
      destruction while still is use by some process(es).  PR 49504.
      [Yann Ylavic]

Modified: apr/apr/trunk/include/apr_global_mutex.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_global_mutex.h?rev=1733775&r1=1733774&r2=1733775&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_global_mutex.h (original)
+++ apr/apr/trunk/include/apr_global_mutex.h Sun Mar  6 00:19:51 2016
@@ -141,10 +141,16 @@ APR_DECLARE(apr_status_t) apr_global_mut
 APR_DECLARE(const char *) apr_global_mutex_lockfile(apr_global_mutex_t *mutex);
 
 /**
- * Display the name of the mutex, as it relates to the actual method used
- * for the underlying apr_proc_mutex_t, if any.  NULL is returned if
- * there is no underlying apr_proc_mutex_t.
- * @param mutex the name of the mutex
+ * Get the mechanism of the mutex, as it relates to the actual method
+ * used for the underlying apr_proc_mutex_t.
+ * @param mutex the mutex to get the mechanism from.
+ */
+APR_DECLARE(apr_lockmech_e) apr_global_mutex_mech(apr_global_mutex_t *mutex);
+
+/**
+ * Get the mechanism's name of the mutex, as it relates to the actual method
+ * used for the underlying apr_proc_mutex_t.
+ * @param mutex the mutex to get the mechanism's name from.
  */
 APR_DECLARE(const char *) apr_global_mutex_name(apr_global_mutex_t *mutex);
 
@@ -174,7 +180,9 @@ APR_POOL_DECLARE_ACCESSOR(global_mutex);
 #define apr_global_mutex_unlock     apr_proc_mutex_unlock
 #define apr_global_mutex_destroy    apr_proc_mutex_destroy
 #define apr_global_mutex_lockfile   apr_proc_mutex_lockfile
+#define apr_global_mutex_mech       apr_proc_mutex_mech
 #define apr_global_mutex_name       apr_proc_mutex_name
+#define apr_global_mutex_perms_set  apr_proc_mutex_perms_set
 #define apr_global_mutex_pool_get   apr_proc_mutex_pool_get
 
 #endif

Modified: apr/apr/trunk/include/apr_portable.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_portable.h?rev=1733775&r1=1733774&r2=1733775&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_portable.h (original)
+++ apr/apr/trunk/include/apr_portable.h Sun Mar  6 00:19:51 2016
@@ -46,6 +46,9 @@
 #if APR_HAVE_PTHREAD_H
 #include <pthread.h>
 #endif
+#if APR_HAVE_SEMAPHORE_H
+#include <semaphore.h>
+#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -140,6 +143,10 @@ struct apr_os_proc_mutex_t {
     pthread_mutex_t *intraproc;
 #endif
 #endif
+#if APR_HAS_POSIXSEM_SERIALIZE
+    /** Value used for POSIX semaphores serialization */
+    sem_t *psem_interproc;
+#endif
 };
 
 typedef int                   apr_os_file_t;        /**< native file */
@@ -241,7 +248,7 @@ APR_DECLARE(apr_status_t) apr_os_sock_ge
                                           apr_socket_t *sock);
 
 /**
- * Convert the proc mutex from os specific type to apr type
+ * Convert the proc mutex from apr type to os specific type
  * @param ospmutex The os specific proc mutex we are converting to.
  * @param pmutex The apr proc mutex to convert.
  */
@@ -249,6 +256,19 @@ APR_DECLARE(apr_status_t) apr_os_proc_mu
                                                 apr_proc_mutex_t *pmutex);
 
 /**
+ * Convert the proc mutex from apr type to os specific type, also
+ * providing the mechanism used by the apr mutex.
+ * @param ospmutex The os specific proc mutex we are converting to.
+ * @param pmutex The apr proc mutex to convert.
+ * @param mech The mechanism used by the apr proc mutex (if not NULL).
+ * @remark Allows for disambiguation for platforms with multiple mechanisms
+ *         available.
+ */
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_get_ex(apr_os_proc_mutex_t *ospmutex, 
+                                                   apr_proc_mutex_t *pmutex,
+                                                   apr_lockmech_e *mech);
+
+/**
  * Get the exploded time in the platforms native format.
  * @param ostime the native time format
  * @param aprtime the time to convert
@@ -419,6 +439,21 @@ APR_DECLARE(apr_status_t) apr_os_proc_mu
                                                 apr_pool_t *cont); 
 
 /**
+ * Convert the proc mutex from os specific type to apr type, using the
+ * specified mechanism.
+ * @param pmutex The apr proc mutex we are converting to.
+ * @param ospmutex The os specific proc mutex to convert.
+ * @param mech The apr mutex locking mechanism
+ * @param cont The pool to use if it is needed.
+ * @remark Allows for disambiguation for platforms with multiple mechanisms
+ *         available.
+ */
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_put_ex(apr_proc_mutex_t **pmutex,
+                                                apr_os_proc_mutex_t *ospmutex,
+                                                apr_lockmech_e mech,
+                                                apr_pool_t *cont); 
+
+/**
  * Put the imploded time in the APR format.
  * @param aprtime the APR time format
  * @param ostime the time to convert

Modified: apr/apr/trunk/include/apr_proc_mutex.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_proc_mutex.h?rev=1733775&r1=1733774&r2=1733775&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_proc_mutex.h (original)
+++ apr/apr/trunk/include/apr_proc_mutex.h Sun Mar  6 00:19:51 2016
@@ -154,9 +154,16 @@ APR_DECLARE(apr_status_t) apr_proc_mutex
 APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *mutex);
 
 /**
- * Display the name of the mutex, as it relates to the actual method used.
- * This matches the valid options for Apache's AcceptMutex directive
- * @param mutex the name of the mutex
+ * Get the mechanism of the mutex, as it relates to the actual method
+ * used for the underlying apr_proc_mutex_t.
+ * @param mutex the mutex to get the mechanism from.
+ */
+APR_DECLARE(apr_lockmech_e) apr_proc_mutex_mech(apr_proc_mutex_t *mutex);
+
+/**
+ * Get the mechanism's name of the mutex, as it relates to the actual method
+ * used for the underlying apr_proc_mutex_t.
+ * @param mutex the mutex to get the mechanism's name from.
  */
 APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex);
 

Modified: apr/apr/trunk/include/arch/unix/apr_arch_proc_mutex.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/arch/unix/apr_arch_proc_mutex.h?rev=1733775&r1=1733774&r2=1733775&view=diff
==============================================================================
--- apr/apr/trunk/include/arch/unix/apr_arch_proc_mutex.h (original)
+++ apr/apr/trunk/include/arch/unix/apr_arch_proc_mutex.h Sun Mar  6 00:19:51 2016
@@ -63,9 +63,6 @@
 #if APR_HAVE_PTHREAD_H
 #include <pthread.h>
 #endif
-#if APR_HAVE_SEMAPHORE_H
-#include <semaphore.h>
-#endif
 /* End System Headers */
 
 struct apr_proc_mutex_unix_lock_methods_t {
@@ -78,6 +75,7 @@ struct apr_proc_mutex_unix_lock_methods_
     apr_status_t (*cleanup)(void *);
     apr_status_t (*child_init)(apr_proc_mutex_t **, apr_pool_t *, const char *);
     apr_status_t (*perms_set)(apr_proc_mutex_t *, apr_fileperms_t, apr_uid_t, apr_gid_t);
+    apr_lockmech_e mech;
     const char *name;
 };
 typedef struct apr_proc_mutex_unix_lock_methods_t apr_proc_mutex_unix_lock_methods_t;
@@ -96,17 +94,24 @@ union semun {
 struct apr_proc_mutex_t {
     apr_pool_t *pool;
     const apr_proc_mutex_unix_lock_methods_t *meth;
-    const apr_proc_mutex_unix_lock_methods_t *inter_meth;
     int curr_locked;
     char *fname;
-#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
-    apr_file_t *interproc;
-#endif
-#if APR_HAS_POSIXSEM_SERIALIZE
-    sem_t *psem_interproc;
+
+    apr_os_proc_mutex_t os;     /* Native mutex holder. */
+
+#if APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
+    apr_file_t *interproc;      /* For apr_file_ calls on native fd. */
+    int interproc_closing;      /* whether the native fd is opened/closed with
+                                 * 'interproc' or apr_os_file_put()ed (hence
+                                 * needing an an explicit close for consistency
+                                 * with other methods).
+                                 */
 #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/trunk/locks/beos/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/beos/proc_mutex.c?rev=1733775&r1=1733774&r2=1733775&view=diff
==============================================================================
--- apr/apr/trunk/locks/beos/proc_mutex.c (original)
+++ apr/apr/trunk/locks/beos/proc_mutex.c Sun Mar  6 00:19:51 2016
@@ -182,6 +182,11 @@ APR_DECLARE(const char *) apr_proc_mutex
     return NULL;
 }
 
+APR_DECLARE(apr_lockmech_e) apr_proc_mutex_mech(apr_proc_mutex_t *mutex)
+{
+    return APR_LOCK_DEFAULT_TIMED;
+}
+
 APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
 {
     return "beossem";
@@ -198,21 +203,35 @@ APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
 
 /* Implement OS-specific accessors defined in apr_portable.h */
 
-APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
-                                                apr_proc_mutex_t *pmutex)
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_get_ex(apr_os_proc_mutex_t *ospmutex, 
+                                                   apr_proc_mutex_t *pmutex,
+                                                   apr_lockmech_e *mech)
 {
     ospmutex->sem = pmutex->Lock;
     ospmutex->ben = pmutex->LockCount;
+    if (mech) {
+        *mech = APR_LOCK_DEFAULT_TIMED;
+    }
     return APR_SUCCESS;
 }
 
-APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
+                                                apr_proc_mutex_t *pmutex)
+{
+    return apr_os_proc_mutex_get_ex(ospmutex, pmutex, NULL);
+}
+
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_put_ex(apr_proc_mutex_t **pmutex,
                                                 apr_os_proc_mutex_t *ospmutex,
+                                                apr_lockmech_e mech,
                                                 apr_pool_t *pool)
 {
     if (pool == NULL) {
         return APR_ENOPOOL;
     }
+    if (mech != APR_LOCK_DEFAULT && mech != APR_LOCK_DEFAULT_TIMED) {
+        return APR_ENOTIMPL;
+    }
     if ((*pmutex) == NULL) {
         (*pmutex) = (apr_proc_mutex_t *)apr_pcalloc(pool, sizeof(apr_proc_mutex_t));
         (*pmutex)->pool = pool;
@@ -222,3 +241,10 @@ APR_DECLARE(apr_status_t) apr_os_proc_mu
     return APR_SUCCESS;
 }
 
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
+                                                apr_os_proc_mutex_t *ospmutex,
+                                                apr_pool_t *pool)
+{
+    return apr_os_proc_mutex_put_ex(pmutex, ospmutex, APR_LOCK_DEFAULT_TIMED, pool);
+}
+

Modified: apr/apr/trunk/locks/netware/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/netware/proc_mutex.c?rev=1733775&r1=1733774&r2=1733775&view=diff
==============================================================================
--- apr/apr/trunk/locks/netware/proc_mutex.c (original)
+++ apr/apr/trunk/locks/netware/proc_mutex.c Sun Mar  6 00:19:51 2016
@@ -105,6 +105,11 @@ APR_DECLARE(const char *) apr_proc_mutex
     return NULL;
 }
 
+APR_DECLARE(apr_lockmech_e) apr_proc_mutex_mech(apr_proc_mutex_t *mutex)
+{
+    return APR_LOCK_DEFAULT;
+}
+
 APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
 {
     return "netwarethread";
@@ -121,18 +126,65 @@ APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
 
 /* Implement OS-specific accessors defined in apr_portable.h */
 
-apr_status_t apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
-                                   apr_proc_mutex_t *pmutex)
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_get_ex(apr_os_proc_mutex_t *ospmutex, 
+                                                   apr_proc_mutex_t *pmutex,
+                                                   apr_lockmech_e *mech)
+{
+#if 1
+    /* We need to change apr_os_proc_mutex_t to a pointer type
+     * to be able to implement this function.
+     */
+    return APR_ENOTIMPL;
+#else
+    if (!pmutex->mutex) {
+        return APR_ENOLOCK;
+    }
+    *ospmutex = pmutex->mutex->mutex;
+    if (mech) {
+        *mech = APR_LOCK_DEFAULT;
+    }
+    return APR_SUCCESS;
+#endif
+}
+
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
+                                                apr_proc_mutex_t *pmutex)
 {
-    if (pmutex)
-        ospmutex = pmutex->mutex->mutex;
-    return APR_ENOLOCK;
+    return apr_os_proc_mutex_get_ex(ospmutex, pmutex, NULL);
 }
 
-apr_status_t apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
-                                   apr_os_proc_mutex_t *ospmutex,
-                                   apr_pool_t *pool)
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_put_ex(apr_proc_mutex_t **pmutex,
+                                                apr_os_proc_mutex_t *ospmutex,
+                                                apr_lockmech_e mech,
+                                                apr_pool_t *pool)
 {
+    if (pool == NULL) {
+        return APR_ENOPOOL;
+    }
+    if (mech != APR_LOCK_DEFAULT) {
+        return APR_ENOTIMPL;
+    }
+#if 1
+    /* We need to change apr_os_proc_mutex_t to a pointer type
+     * to be able to implement this function.
+     */
     return APR_ENOTIMPL;
+#else
+    if ((*pmutex) == NULL) {
+        (*pmutex) = apr_pcalloc(pool, sizeof(apr_proc_mutex_t));
+        (*pmutex)->pool = pool;
+    }
+    (*pmutex)->mutex = apr_pcalloc(pool, sizeof(apr_thread_mutex_t));
+    (*pmutex)->mutex->mutex = *ospmutex;
+    (*pmutex)->mutex->pool = pool;
+    return APR_SUCCESS;
+#endif
+}
+
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
+                                                apr_os_proc_mutex_t *ospmutex,
+                                                apr_pool_t *pool)
+{
+    return apr_os_proc_mutex_put_ex(pmutex, ospmutex, APR_LOCK_DEFAULT, pool);
 }
 

Modified: apr/apr/trunk/locks/os2/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/os2/proc_mutex.c?rev=1733775&r1=1733774&r2=1733775&view=diff
==============================================================================
--- apr/apr/trunk/locks/os2/proc_mutex.c (original)
+++ apr/apr/trunk/locks/os2/proc_mutex.c Sun Mar  6 00:19:51 2016
@@ -60,6 +60,11 @@ APR_DECLARE(const char *) apr_proc_mutex
     return NULL;
 }
 
+APR_DECLARE(apr_lockmech_e) apr_proc_mutex_mech(apr_proc_mutex_t *mutex)
+{
+    return APR_LOCK_DEFAULT_TIMED;
+}
+
 APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
 {
     return "os2sem";
@@ -243,20 +248,35 @@ APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
 
 /* Implement OS-specific accessors defined in apr_portable.h */
 
-APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
-                                                apr_proc_mutex_t *pmutex)
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_get_ex(apr_os_proc_mutex_t *ospmutex, 
+                                                   apr_proc_mutex_t *pmutex,
+                                                   apr_lockmech_e *mech)
 {
     *ospmutex = pmutex->hMutex;
-    return APR_ENOTIMPL;
+    if (mech) {
+        *mech = APR_LOCK_DEFAULT_TIMED;
+    }
+    return APR_SUCCESS;
 }
 
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
+                                                apr_proc_mutex_t *pmutex)
+{
+    return apr_os_proc_mutex_get_ex(ospmutex, pmutex, NULL);
+}
 
-
-APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_put_ex(apr_proc_mutex_t **pmutex,
                                                 apr_os_proc_mutex_t *ospmutex,
+                                                apr_lockmech_e mech,
                                                 apr_pool_t *pool)
 {
     apr_proc_mutex_t *new;
+    if (pool == NULL) {
+        return APR_ENOPOOL;
+    }
+    if (mech != APR_LOCK_DEFAULT && mech != APR_LOCK_DEFAULT_TIMED) {
+        return APR_ENOTIMPL;
+    }
 
     new = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
     new->pool       = pool;
@@ -268,3 +288,10 @@ APR_DECLARE(apr_status_t) apr_os_proc_mu
     return APR_SUCCESS;
 }
 
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
+                                                apr_os_proc_mutex_t *ospmutex,
+                                                apr_pool_t *pool)
+{
+    return apr_os_proc_mutex_put_ex(pmutex, ospmutex, APR_LOCK_DEFAULT_TIMED, pool);
+}
+

Modified: apr/apr/trunk/locks/unix/global_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/global_mutex.c?rev=1733775&r1=1733774&r2=1733775&view=diff
==============================================================================
--- apr/apr/trunk/locks/unix/global_mutex.c (original)
+++ apr/apr/trunk/locks/unix/global_mutex.c Sun Mar  6 00:19:51 2016
@@ -15,6 +15,7 @@
  */
 
 #include "apr.h"
+
 #include "apr_strings.h"
 #include "apr_arch_global_mutex.h"
 #include "apr_proc_mutex.h"
@@ -59,7 +60,7 @@ APR_DECLARE(apr_status_t) apr_global_mut
     }
 
 #if APR_HAS_THREADS
-    if (m->proc_mutex->inter_meth->flags & APR_PROCESS_LOCK_MECH_IS_GLOBAL) {
+    if (m->proc_mutex->meth->flags & APR_PROCESS_LOCK_MECH_IS_GLOBAL) {
         m->thread_mutex = NULL; /* We don't need a thread lock. */
     }
     else {
@@ -214,6 +215,11 @@ APR_DECLARE(const char *) apr_global_mut
     return apr_proc_mutex_lockfile(mutex->proc_mutex);
 }
 
+APR_DECLARE(apr_lockmech_e) apr_global_mutex_mech(apr_global_mutex_t *mutex)
+{
+    return apr_proc_mutex_mech(mutex->proc_mutex);
+}
+
 APR_DECLARE(const char *) apr_global_mutex_name(apr_global_mutex_t *mutex)
 {
     return apr_proc_mutex_name(mutex->proc_mutex);
@@ -229,3 +235,4 @@ APR_PERMS_SET_IMPLEMENT(global_mutex)
 }
 
 APR_POOL_IMPLEMENT_ACCESSOR(global_mutex)
+

Modified: apr/apr/trunk/locks/unix/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/proc_mutex.c?rev=1733775&r1=1733774&r2=1733775&view=diff
==============================================================================
--- apr/apr/trunk/locks/unix/proc_mutex.c (original)
+++ apr/apr/trunk/locks/unix/proc_mutex.c Sun Mar  6 00:19:51 2016
@@ -57,7 +57,7 @@ static apr_status_t proc_mutex_posix_cle
 {
     apr_proc_mutex_t *mutex = mutex_;
     
-    if (sem_close(mutex->psem_interproc) < 0) {
+    if (sem_close(mutex->os.psem_interproc) < 0) {
         return errno;
     }
 
@@ -72,8 +72,6 @@ static apr_status_t proc_mutex_posix_cre
     sem_t *psem;
     char semname[APR_MD5_DIGESTSIZE * 2 + 2];
     
-    new_mutex->interproc = apr_palloc(new_mutex->pool,
-                                      sizeof(*new_mutex->interproc));
     /*
      * This bogusness is to follow what appears to be the
      * lowest common denominator in Posix semaphore naming:
@@ -136,7 +134,7 @@ static apr_status_t proc_mutex_posix_cre
     }
     /* Ahhh. The joys of Posix sems. Predelete it... */
     sem_unlink(semname);
-    new_mutex->psem_interproc = psem;
+    new_mutex->os.psem_interproc = psem;
     new_mutex->fname = apr_pstrdup(new_mutex->pool, semname);
     apr_pool_cleanup_register(new_mutex->pool, (void *)new_mutex,
                               apr_proc_mutex_cleanup, 
@@ -149,7 +147,7 @@ static apr_status_t proc_mutex_posix_acq
     int rc;
 
     do {
-        rc = sem_wait(mutex->psem_interproc);
+        rc = sem_wait(mutex->os.psem_interproc);
     } while (rc < 0 && errno == EINTR);
     if (rc < 0) {
         return errno;
@@ -163,7 +161,7 @@ static apr_status_t proc_mutex_posix_try
     int rc;
 
     do {
-        rc = sem_trywait(mutex->psem_interproc);
+        rc = sem_trywait(mutex->os.psem_interproc);
     } while (rc < 0 && errno == EINTR);
     if (rc < 0) {
         if (errno == EAGAIN) {
@@ -194,7 +192,7 @@ static apr_status_t proc_mutex_posix_tim
         abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */
         
         do {
-            rc = sem_timedwait(mutex->psem_interproc, &abstime);
+            rc = sem_timedwait(mutex->os.psem_interproc, &abstime);
         } while (rc < 0 && errno == EINTR);
         if (rc < 0) {
             if (errno == ETIMEDOUT) {
@@ -213,7 +211,7 @@ static apr_status_t proc_mutex_posix_tim
 static apr_status_t proc_mutex_posix_release(apr_proc_mutex_t *mutex)
 {
     mutex->curr_locked = 0;
-    if (sem_post(mutex->psem_interproc) < 0) {
+    if (sem_post(mutex->os.psem_interproc) < 0) {
         /* any failure is probably fatal, so no big deal to leave
          * ->curr_locked at 0. */
         return errno;
@@ -236,6 +234,7 @@ static const apr_proc_mutex_unix_lock_me
     proc_mutex_posix_cleanup,
     proc_mutex_no_child_init,
     proc_mutex_no_perms_set,
+    APR_LOCK_POSIXSEM,
     "posixsem"
 };
 
@@ -265,9 +264,9 @@ static apr_status_t proc_mutex_sysv_clea
     apr_proc_mutex_t *mutex=mutex_;
     union semun ick;
     
-    if (mutex->interproc->filedes != -1) {
+    if (mutex->os.crossproc != -1) {
         ick.val = 0;
-        semctl(mutex->interproc->filedes, 0, IPC_RMID, ick);
+        semctl(mutex->os.crossproc, 0, IPC_RMID, ick);
     }
     return APR_SUCCESS;
 }    
@@ -278,18 +277,17 @@ static apr_status_t proc_mutex_sysv_crea
     union semun ick;
     apr_status_t rv;
     
-    new_mutex->interproc = apr_palloc(new_mutex->pool, sizeof(*new_mutex->interproc));
-    new_mutex->interproc->filedes = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
-
-    if (new_mutex->interproc->filedes < 0) {
+    new_mutex->os.crossproc = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
+    if (new_mutex->os.crossproc == -1) {
         rv = errno;
         proc_mutex_sysv_cleanup(new_mutex);
         return rv;
     }
     ick.val = 1;
-    if (semctl(new_mutex->interproc->filedes, 0, SETVAL, ick) < 0) {
+    if (semctl(new_mutex->os.crossproc, 0, SETVAL, ick) < 0) {
         rv = errno;
         proc_mutex_sysv_cleanup(new_mutex);
+        new_mutex->os.crossproc = -1;
         return rv;
     }
     new_mutex->curr_locked = 0;
@@ -304,7 +302,7 @@ static apr_status_t proc_mutex_sysv_acqu
     int rc;
 
     do {
-        rc = semop(mutex->interproc->filedes, &proc_mutex_op_on, 1);
+        rc = semop(mutex->os.crossproc, &proc_mutex_op_on, 1);
     } while (rc < 0 && errno == EINTR);
     if (rc < 0) {
         return errno;
@@ -318,7 +316,7 @@ static apr_status_t proc_mutex_sysv_trya
     int rc;
 
     do {
-        rc = semop(mutex->interproc->filedes, &proc_mutex_op_try, 1);
+        rc = semop(mutex->os.crossproc, &proc_mutex_op_try, 1);
     } while (rc < 0 && errno == EINTR);
     if (rc < 0) {
         if (errno == EAGAIN) {
@@ -347,7 +345,7 @@ static apr_status_t proc_mutex_sysv_time
         abstime.tv_sec = apr_time_sec(timeout);
         abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */
         do {
-            rc = semtimedop(mutex->interproc->filedes, &proc_mutex_op_on, 1,
+            rc = semtimedop(mutex->os.crossproc, &proc_mutex_op_on, 1,
                             &abstime);
         } while (rc < 0 && errno == EINTR);
         if (rc < 0) {
@@ -370,7 +368,7 @@ static apr_status_t proc_mutex_sysv_rele
 
     mutex->curr_locked = 0;
     do {
-        rc = semop(mutex->interproc->filedes, &proc_mutex_op_off, 1);
+        rc = semop(mutex->os.crossproc, &proc_mutex_op_off, 1);
     } while (rc < 0 && errno == EINTR);
     if (rc < 0) {
         return errno;
@@ -390,7 +388,7 @@ static apr_status_t proc_mutex_sysv_perm
     buf.sem_perm.gid = gid;
     buf.sem_perm.mode = apr_unix_perms2mode(perms);
     ick.buf = &buf;
-    if (semctl(mutex->interproc->filedes, 0, IPC_SET, ick) < 0) {
+    if (semctl(mutex->os.crossproc, 0, IPC_SET, ick) < 0) {
         return errno;
     }
     return APR_SUCCESS;
@@ -411,6 +409,7 @@ static const apr_proc_mutex_unix_lock_me
     proc_mutex_sysv_cleanup,
     proc_mutex_no_child_init,
     proc_mutex_sysv_perms_set,
+    APR_LOCK_SYSVSEM,
     "sysvsem"
 };
 
@@ -433,7 +432,24 @@ typedef struct {
 } proc_pthread_mutex_t;
 
 #define proc_pthread_mutex_refcount(m) \
-    (((proc_pthread_mutex_t *)(m)->pthread_interproc)->refcount)
+    (((proc_pthread_mutex_t *)(m)->os.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_)
 {
@@ -441,15 +457,15 @@ static apr_status_t proc_pthread_mutex_u
     apr_status_t rv;
 
     if (mutex->curr_locked == 1) {
-        if ((rv = pthread_mutex_unlock(mutex->pthread_interproc))) {
+        if ((rv = pthread_mutex_unlock(mutex->os.pthread_interproc))) {
 #ifdef HAVE_ZOS_PTHREADS
             rv = errno;
 #endif
             return rv;
         }
     }
-    if (!apr_atomic_dec32(&proc_pthread_mutex_refcount(mutex))) {
-        if ((rv = pthread_mutex_destroy(mutex->pthread_interproc))) {
+    if (!proc_pthread_mutex_dec(mutex)) {
+        if ((rv = pthread_mutex_destroy(mutex->os.pthread_interproc))) {
 #ifdef HAVE_ZOS_PTHREADS
             rv = errno;
 #endif
@@ -470,7 +486,7 @@ static apr_status_t proc_mutex_proc_pthr
             return rv;
         }
     }
-    if (munmap((caddr_t)mutex->pthread_interproc, sizeof(pthread_mutex_t))) {
+    if (munmap(mutex->os.pthread_interproc, sizeof(proc_pthread_mutex_t))) {
         return errno;
     }
     return APR_SUCCESS;
@@ -488,16 +504,16 @@ 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->os.pthread_interproc = mmap(NULL, sizeof(proc_pthread_mutex_t),
+                                           PROT_READ | PROT_WRITE, MAP_SHARED,
+                                           fd, 0); 
+    if (new_mutex->os.pthread_interproc == MAP_FAILED) {
+        new_mutex->os.pthread_interproc = NULL;
+        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 */
 
@@ -537,7 +553,7 @@ static apr_status_t proc_mutex_proc_pthr
     }
 #endif /* HAVE_PTHREAD_MUTEX_ROBUST */
 
-    if ((rv = pthread_mutex_init(new_mutex->pthread_interproc, &mattr))) {
+    if ((rv = pthread_mutex_init(new_mutex->os.pthread_interproc, &mattr))) {
 #ifdef HAVE_ZOS_PTHREADS
         rv = errno;
 #endif
@@ -569,9 +585,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;
 }
 
@@ -579,15 +596,15 @@ static apr_status_t proc_mutex_proc_pthr
 {
     apr_status_t rv;
 
-    if ((rv = pthread_mutex_lock(mutex->pthread_interproc))) {
+    if ((rv = pthread_mutex_lock(mutex->os.pthread_interproc))) {
 #ifdef HAVE_ZOS_PTHREADS
         rv = errno;
 #endif
 #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));
-            pthread_mutex_consistent_np(mutex->pthread_interproc);
+            proc_pthread_mutex_dec(mutex);
+            pthread_mutex_consistent_np(mutex->os.pthread_interproc);
         }
         else
 #endif
@@ -601,7 +618,7 @@ static apr_status_t proc_mutex_proc_pthr
 {
     apr_status_t rv;
  
-    if ((rv = pthread_mutex_trylock(mutex->pthread_interproc))) {
+    if ((rv = pthread_mutex_trylock(mutex->os.pthread_interproc))) {
 #ifdef HAVE_ZOS_PTHREADS 
         rv = errno;
 #endif
@@ -611,8 +628,8 @@ 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));
-            pthread_mutex_consistent_np(mutex->pthread_interproc);
+            proc_pthread_mutex_dec(mutex);
+            pthread_mutex_consistent_np(mutex->os.pthread_interproc);
         }
         else
 #endif
@@ -640,7 +657,7 @@ proc_mutex_proc_pthread_timedacquire(apr
         abstime.tv_sec = apr_time_sec(timeout);
         abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */
 
-        if ((rv = pthread_mutex_timedlock(mutex->pthread_interproc,
+        if ((rv = pthread_mutex_timedlock(mutex->os.pthread_interproc,
                                           &abstime))) {
 #ifdef HAVE_ZOS_PTHREADS 
             rv = errno;
@@ -651,8 +668,8 @@ proc_mutex_proc_pthread_timedacquire(apr
 #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));
-                pthread_mutex_consistent_np(mutex->pthread_interproc);
+                proc_pthread_mutex_dec(mutex);
+                pthread_mutex_consistent_np(mutex->os.pthread_interproc);
             }
             else
 #endif
@@ -668,7 +685,7 @@ static apr_status_t proc_mutex_proc_pthr
     apr_status_t rv;
 
     mutex->curr_locked = 0;
-    if ((rv = pthread_mutex_unlock(mutex->pthread_interproc))) {
+    if ((rv = pthread_mutex_unlock(mutex->os.pthread_interproc))) {
 #ifdef HAVE_ZOS_PTHREADS
         rv = errno;
 #endif
@@ -688,6 +705,7 @@ static const apr_proc_mutex_unix_lock_me
     proc_mutex_proc_pthread_cleanup,
     proc_mutex_proc_pthread_child_init,
     proc_mutex_no_perms_set,
+    APR_LOCK_PROC_PTHREAD,
     "pthread"
 };
 
@@ -716,7 +734,7 @@ static void proc_mutex_fcntl_setup(void)
 
 static apr_status_t proc_mutex_fcntl_cleanup(void *mutex_)
 {
-    apr_status_t status;
+    apr_status_t status = APR_SUCCESS;
     apr_proc_mutex_t *mutex=mutex_;
 
     if (mutex->curr_locked == 1) {
@@ -725,7 +743,16 @@ static apr_status_t proc_mutex_fcntl_cle
             return status;
     }
         
-    return apr_file_close(mutex->interproc);
+    if (mutex->interproc) {
+        status = apr_file_close(mutex->interproc);
+    }
+    if (!mutex->interproc_closing
+            && mutex->os.crossproc != -1
+            && close(mutex->os.crossproc) == -1
+            && status == APR_SUCCESS) {
+        status = errno;
+    }
+    return status;
 }    
 
 static apr_status_t proc_mutex_fcntl_create(apr_proc_mutex_t *new_mutex,
@@ -751,6 +778,8 @@ static apr_status_t proc_mutex_fcntl_cre
         return rv;
     }
 
+    new_mutex->os.crossproc = new_mutex->interproc->filedes;
+    new_mutex->interproc_closing = 1;
     new_mutex->curr_locked = 0;
     unlink(new_mutex->fname);
     apr_pool_cleanup_register(new_mutex->pool,
@@ -765,7 +794,7 @@ static apr_status_t proc_mutex_fcntl_acq
     int rc;
 
     do {
-        rc = fcntl(mutex->interproc->filedes, F_SETLKW, &proc_mutex_lock_it);
+        rc = fcntl(mutex->os.crossproc, F_SETLKW, &proc_mutex_lock_it);
     } while (rc < 0 && errno == EINTR);
     if (rc < 0) {
         return errno;
@@ -779,7 +808,7 @@ static apr_status_t proc_mutex_fcntl_try
     int rc;
 
     do {
-        rc = fcntl(mutex->interproc->filedes, F_SETLK, &proc_mutex_lock_it);
+        rc = fcntl(mutex->os.crossproc, F_SETLK, &proc_mutex_lock_it);
     } while (rc < 0 && errno == EINTR);
     if (rc < 0) {
 #if FCNTL_TRYACQUIRE_EACCES
@@ -808,7 +837,7 @@ static apr_status_t proc_mutex_fcntl_rel
 
     mutex->curr_locked=0;
     do {
-        rc = fcntl(mutex->interproc->filedes, F_SETLKW, &proc_mutex_unlock_it);
+        rc = fcntl(mutex->os.crossproc, F_SETLKW, &proc_mutex_unlock_it);
     } while (rc < 0 && errno == EINTR);
     if (rc < 0) {
         return errno;
@@ -825,7 +854,7 @@ static apr_status_t proc_mutex_fcntl_per
     if (mutex->fname) {
         if (!(perms & APR_FPROT_GSETID))
             gid = -1;
-        if (fchown(mutex->interproc->filedes, uid, gid) < 0) {
+        if (fchown(mutex->os.crossproc, uid, gid) < 0) {
             return errno;
         }
     }
@@ -847,6 +876,7 @@ static const apr_proc_mutex_unix_lock_me
     proc_mutex_fcntl_cleanup,
     proc_mutex_no_child_init,
     proc_mutex_fcntl_perms_set,
+    APR_LOCK_FCNTL,
     "fcntl"
 };
 
@@ -858,7 +888,7 @@ static apr_status_t proc_mutex_flock_rel
 
 static apr_status_t proc_mutex_flock_cleanup(void *mutex_)
 {
-    apr_status_t status;
+    apr_status_t status = APR_SUCCESS;
     apr_proc_mutex_t *mutex=mutex_;
 
     if (mutex->curr_locked == 1) {
@@ -867,10 +897,18 @@ static apr_status_t proc_mutex_flock_cle
             return status;
     }
     if (mutex->interproc) { /* if it was opened properly */
-        apr_file_close(mutex->interproc);
+        status = apr_file_close(mutex->interproc);
     }
-    unlink(mutex->fname);
-    return APR_SUCCESS;
+    if (!mutex->interproc_closing
+            && mutex->os.crossproc != -1
+            && close(mutex->os.crossproc) == -1
+            && status == APR_SUCCESS) {
+        status = errno;
+    }
+    if (mutex->fname) {
+        unlink(mutex->fname);
+    }
+    return status;
 }    
 
 static apr_status_t proc_mutex_flock_create(apr_proc_mutex_t *new_mutex,
@@ -894,8 +932,11 @@ static apr_status_t proc_mutex_flock_cre
  
     if (rv != APR_SUCCESS) {
         proc_mutex_flock_cleanup(new_mutex);
-        return errno;
+        return rv;
     }
+
+    new_mutex->os.crossproc = new_mutex->interproc->filedes;
+    new_mutex->interproc_closing = 1;
     new_mutex->curr_locked = 0;
     apr_pool_cleanup_register(new_mutex->pool, (void *)new_mutex,
                               apr_proc_mutex_cleanup,
@@ -908,7 +949,7 @@ static apr_status_t proc_mutex_flock_acq
     int rc;
 
     do {
-        rc = flock(mutex->interproc->filedes, LOCK_EX);
+        rc = flock(mutex->os.crossproc, LOCK_EX);
     } while (rc < 0 && errno == EINTR);
     if (rc < 0) {
         return errno;
@@ -922,7 +963,7 @@ static apr_status_t proc_mutex_flock_try
     int rc;
 
     do {
-        rc = flock(mutex->interproc->filedes, LOCK_EX | LOCK_NB);
+        rc = flock(mutex->os.crossproc, LOCK_EX | LOCK_NB);
     } while (rc < 0 && errno == EINTR);
     if (rc < 0) {
         if (errno == EWOULDBLOCK || errno == EAGAIN) {
@@ -947,7 +988,7 @@ static apr_status_t proc_mutex_flock_rel
 
     mutex->curr_locked = 0;
     do {
-        rc = flock(mutex->interproc->filedes, LOCK_UN);
+        rc = flock(mutex->os.crossproc, LOCK_UN);
     } while (rc < 0 && errno == EINTR);
     if (rc < 0) {
         return errno;
@@ -962,19 +1003,25 @@ 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;
+        if (!fname) {
+            return APR_SUCCESS;
+        }
     }
+
+    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);
     if (rv != APR_SUCCESS) {
         return rv;
     }
+    new_mutex->os.crossproc = new_mutex->interproc->filedes;
+    new_mutex->interproc_closing = 1;
+
     *mutex = new_mutex;
     return APR_SUCCESS;
 }
@@ -988,7 +1035,7 @@ static apr_status_t proc_mutex_flock_per
     if (mutex->fname) {
         if (!(perms & APR_FPROT_GSETID))
             gid = -1;
-        if (fchown(mutex->interproc->filedes, uid, gid) < 0) {
+        if (fchown(mutex->os.crossproc, uid, gid) < 0) {
             return errno;
         }
     }
@@ -1010,6 +1057,7 @@ static const apr_proc_mutex_unix_lock_me
     proc_mutex_flock_cleanup,
     proc_mutex_flock_child_init,
     proc_mutex_flock_perms_set,
+    APR_LOCK_FLOCK,
     "flock"
 };
 
@@ -1026,55 +1074,132 @@ void apr_proc_mutex_unix_setup_lock(void
 #endif
 }
 
-static apr_status_t proc_mutex_choose_method(apr_proc_mutex_t *new_mutex, apr_lockmech_e mech)
+static apr_status_t proc_mutex_choose_method(apr_proc_mutex_t *new_mutex,
+                                             apr_lockmech_e mech,
+                                             apr_os_proc_mutex_t *ospmutex)
 {
+#if APR_HAS_PROC_PTHREAD_SERIALIZE
+    new_mutex->os.pthread_interproc = NULL;
+#endif
+#if APR_HAS_POSIXSEM_SERIALIZE
+    new_mutex->os.psem_interproc = NULL;
+#endif
+#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
+    new_mutex->os.crossproc = -1;
+
+#if APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
+    new_mutex->interproc = NULL;
+    new_mutex->interproc_closing = 0;
+#endif
+#endif
+
     switch (mech) {
     case APR_LOCK_FCNTL:
 #if APR_HAS_FCNTL_SERIALIZE
-        new_mutex->inter_meth = &mutex_fcntl_methods;
+        new_mutex->meth = &mutex_fcntl_methods;
+        if (ospmutex) {
+            if (ospmutex->crossproc == -1) {
+                return APR_EINVAL;
+            }
+            new_mutex->os.crossproc = ospmutex->crossproc;
+        }
 #else
         return APR_ENOTIMPL;
 #endif
         break;
     case APR_LOCK_FLOCK:
 #if APR_HAS_FLOCK_SERIALIZE
-        new_mutex->inter_meth = &mutex_flock_methods;
+        new_mutex->meth = &mutex_flock_methods;
+        if (ospmutex) {
+            if (ospmutex->crossproc == -1) {
+                return APR_EINVAL;
+            }
+            new_mutex->os.crossproc = ospmutex->crossproc;
+        }
 #else
         return APR_ENOTIMPL;
 #endif
         break;
     case APR_LOCK_SYSVSEM:
 #if APR_HAS_SYSVSEM_SERIALIZE
-        new_mutex->inter_meth = &mutex_sysv_methods;
+        new_mutex->meth = &mutex_sysv_methods;
+        if (ospmutex) {
+            if (ospmutex->crossproc == -1) {
+                return APR_EINVAL;
+            }
+            new_mutex->os.crossproc = ospmutex->crossproc;
+        }
 #else
         return APR_ENOTIMPL;
 #endif
         break;
     case APR_LOCK_POSIXSEM:
 #if APR_HAS_POSIXSEM_SERIALIZE
-        new_mutex->inter_meth = &mutex_posixsem_methods;
+        new_mutex->meth = &mutex_posixsem_methods;
+        if (ospmutex) {
+            if (ospmutex->psem_interproc == NULL) {
+                return APR_EINVAL;
+            }
+            new_mutex->os.psem_interproc = ospmutex->psem_interproc;
+        }
 #else
         return APR_ENOTIMPL;
 #endif
         break;
     case APR_LOCK_PROC_PTHREAD:
 #if APR_HAS_PROC_PTHREAD_SERIALIZE
-        new_mutex->inter_meth = &mutex_proc_pthread_methods;
+        new_mutex->meth = &mutex_proc_pthread_methods;
+        if (ospmutex) {
+            if (ospmutex->pthread_interproc == NULL) {
+                return APR_EINVAL;
+            }
+            new_mutex->os.pthread_interproc = ospmutex->pthread_interproc;
+        }
 #else
         return APR_ENOTIMPL;
 #endif
         break;
     case APR_LOCK_DEFAULT:
 #if APR_USE_FLOCK_SERIALIZE
-        new_mutex->inter_meth = &mutex_flock_methods;
+        new_mutex->meth = &mutex_flock_methods;
+        if (ospmutex) {
+            if (ospmutex->crossproc == -1) {
+                return APR_EINVAL;
+            }
+            new_mutex->os.crossproc = ospmutex->crossproc;
+        }
 #elif APR_USE_SYSVSEM_SERIALIZE
-        new_mutex->inter_meth = &mutex_sysv_methods;
+        new_mutex->meth = &mutex_sysv_methods;
+        if (ospmutex) {
+            if (ospmutex->crossproc == -1) {
+                return APR_EINVAL;
+            }
+            new_mutex->os.crossproc = ospmutex->crossproc;
+        }
 #elif APR_USE_FCNTL_SERIALIZE
-        new_mutex->inter_meth = &mutex_fcntl_methods;
+        new_mutex->meth = &mutex_fcntl_methods;
+        if (ospmutex) {
+            if (ospmutex->crossproc == -1) {
+                return APR_EINVAL;
+            }
+            new_mutex->os.crossproc = ospmutex->crossproc;
+        }
 #elif APR_USE_PROC_PTHREAD_SERIALIZE
-        new_mutex->inter_meth = &mutex_proc_pthread_methods;
+        new_mutex->meth = &mutex_proc_pthread_methods;
+        if (ospmutex) {
+            if (ospmutex->pthread_interproc == NULL) {
+                return APR_EINVAL;
+            }
+            new_mutex->os.pthread_interproc = ospmutex->pthread_interproc;
+        }
 #elif APR_USE_POSIXSEM_SERIALIZE
-        new_mutex->inter_meth = &mutex_posixsem_methods;
+        new_mutex->meth = &mutex_posixsem_methods;
+        if (ospmutex) {
+            if (ospmutex->psem_interproc == NULL) {
+                return APR_EINVAL;
+            }
+            new_mutex->os.psem_interproc = ospmutex->psem_interproc;
+        }
 #else
         return APR_ENOTIMPL;
 #endif
@@ -1083,13 +1208,13 @@ static apr_status_t proc_mutex_choose_me
 #if APR_HAS_PROC_PTHREAD_SERIALIZE \
             && defined(HAVE_PTHREAD_MUTEX_ROBUST) \
             && defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK)
-        new_mutex->inter_meth = &mutex_proc_pthread_methods;
+        new_mutex->meth = &mutex_proc_pthread_methods;
 #elif APR_HAS_SYSVSEM_SERIALIZE \
             && defined(HAVE_SEMTIMEDOP)
-        new_mutex->inter_meth = &mutex_sysv_methods;
+        new_mutex->meth = &mutex_sysv_methods;
 #elif APR_HAS_POSIXSEM_SERIALIZE \
             && defined(HAVE_SEM_TIMEDWAIT)
-        new_mutex->inter_meth = &mutex_posixsem_methods;
+        new_mutex->meth = &mutex_posixsem_methods;
 #else
         return APR_ENOTIMPL;
 #endif
@@ -1105,10 +1230,10 @@ APR_DECLARE(const char *) apr_proc_mutex
     apr_status_t rv;
     apr_proc_mutex_t mutex;
 
-    if ((rv = proc_mutex_choose_method(&mutex, APR_LOCK_DEFAULT)) != APR_SUCCESS) {
+    if ((rv = proc_mutex_choose_method(&mutex, APR_LOCK_DEFAULT,
+                                       NULL)) != APR_SUCCESS) {
         return "unknown";
     }
-    mutex.meth = mutex.inter_meth;
 
     return apr_proc_mutex_name(&mutex);
 }
@@ -1117,12 +1242,11 @@ static apr_status_t proc_mutex_create(ap
 {
     apr_status_t rv;
 
-    if ((rv = proc_mutex_choose_method(new_mutex, mech)) != APR_SUCCESS) {
+    if ((rv = proc_mutex_choose_method(new_mutex, mech,
+                                       NULL)) != APR_SUCCESS) {
         return rv;
     }
 
-    new_mutex->meth = new_mutex->inter_meth;
-
     if ((rv = new_mutex->meth->create(new_mutex, fname)) != APR_SUCCESS) {
         return rv;
     }
@@ -1182,6 +1306,11 @@ APR_DECLARE(apr_status_t) apr_proc_mutex
     return ((apr_proc_mutex_t *)mutex)->meth->cleanup(mutex);
 }
 
+APR_DECLARE(apr_lockmech_e) apr_proc_mutex_mech(apr_proc_mutex_t *mutex)
+{
+    return mutex->meth->mech;
+}
+
 APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
 {
     return mutex->meth->name;
@@ -1214,27 +1343,29 @@ APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
 
 /* Implement OS-specific accessors defined in apr_portable.h */
 
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_get_ex(apr_os_proc_mutex_t *ospmutex, 
+                                                   apr_proc_mutex_t *pmutex,
+                                                   apr_lockmech_e *mech)
+{
+    *ospmutex = pmutex->os;
+    if (mech) {
+        *mech = pmutex->meth->mech;
+    }
+    return APR_SUCCESS;
+}
+
 APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
                                                 apr_proc_mutex_t *pmutex)
 {
-#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE || APR_HAS_POSIXSEM_SERIALIZE
-    if (pmutex->interproc) {
-        ospmutex->crossproc = pmutex->interproc->filedes;
-    }
-    else {
-        ospmutex->crossproc = -1;
-    }
-#endif
-#if APR_HAS_PROC_PTHREAD_SERIALIZE
-    ospmutex->pthread_interproc = pmutex->pthread_interproc;
-#endif
-    return APR_SUCCESS;
+    return apr_os_proc_mutex_get_ex(ospmutex, pmutex, NULL);
 }
 
-APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_put_ex(apr_proc_mutex_t **pmutex,
                                                 apr_os_proc_mutex_t *ospmutex,
+                                                apr_lockmech_e mech,
                                                 apr_pool_t *pool)
 {
+    apr_status_t rv;
     if (pool == NULL) {
         return APR_ENOPOOL;
     }
@@ -1243,12 +1374,20 @@ APR_DECLARE(apr_status_t) apr_os_proc_mu
                                                     sizeof(apr_proc_mutex_t));
         (*pmutex)->pool = pool;
     }
-#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE || APR_HAS_POSIXSEM_SERIALIZE
-    apr_os_file_put(&(*pmutex)->interproc, &ospmutex->crossproc, 0, pool);
-#endif
-#if APR_HAS_PROC_PTHREAD_SERIALIZE
-    (*pmutex)->pthread_interproc = ospmutex->pthread_interproc;
+    rv = proc_mutex_choose_method(*pmutex, mech, ospmutex);
+#if APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
+    if (rv == APR_SUCCESS) {
+        rv = apr_os_file_put(&(*pmutex)->interproc, &(*pmutex)->os.crossproc,
+                             0, pool);
+    }
 #endif
-    return APR_SUCCESS;
+    return rv;
+}
+
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
+                                                apr_os_proc_mutex_t *ospmutex,
+                                                apr_pool_t *pool)
+{
+    return apr_os_proc_mutex_put_ex(pmutex, ospmutex, APR_LOCK_DEFAULT, pool);
 }
 

Modified: apr/apr/trunk/locks/win32/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/win32/proc_mutex.c?rev=1733775&r1=1733774&r2=1733775&view=diff
==============================================================================
--- apr/apr/trunk/locks/win32/proc_mutex.c (original)
+++ apr/apr/trunk/locks/win32/proc_mutex.c Sun Mar  6 00:19:51 2016
@@ -43,6 +43,10 @@ APR_DECLARE(apr_status_t) apr_proc_mutex
     HANDLE hMutex;
     void *mutexkey;
 
+    if (mech != APR_LOCK_DEFAULT && mech != APR_LOCK_DEFAULT_TIMED) {
+        return APR_ENOTIMPL;
+    }
+
     /* res_name_from_filename turns fname into a pseduo-name
      * without slashes or backslashes, and prepends the \global
      * prefix on Win2K and later
@@ -220,6 +224,11 @@ APR_DECLARE(const char *) apr_proc_mutex
     return mutex->fname;
 }
 
+APR_DECLARE(apr_lockmech_e) apr_proc_mutex_mech(apr_proc_mutex_t *mutex)
+{
+    return APR_LOCK_DEFAULT_TIMED;
+}
+
 APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
 {
     return apr_proc_mutex_defname();
@@ -236,20 +245,34 @@ APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
 
 /* Implement OS-specific accessors defined in apr_portable.h */
 
-APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
-                                                apr_proc_mutex_t *mutex)
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_get_ex(apr_os_proc_mutex_t *ospmutex, 
+                                                   apr_proc_mutex_t *pmutex,
+                                                   apr_lockmech_e *mech)
 {
     *ospmutex = mutex->handle;
+    if (mech) {
+        *mech = APR_LOCK_DEFAULT_TIMED;
+    }
     return APR_SUCCESS;
 }
 
-APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
+                                                apr_proc_mutex_t *pmutex)
+{
+    return apr_os_proc_mutex_get_ex(ospmutex, pmutex, NULL);
+}
+
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_put_ex(apr_proc_mutex_t **pmutex,
                                                 apr_os_proc_mutex_t *ospmutex,
+                                                apr_lockmech_e mech,
                                                 apr_pool_t *pool)
 {
     if (pool == NULL) {
         return APR_ENOPOOL;
     }
+    if (mech != APR_LOCK_DEFAULT && mech != APR_LOCK_DEFAULT_TIMED) {
+        return APR_ENOTIMPL;
+    }
     if ((*pmutex) == NULL) {
         (*pmutex) = (apr_proc_mutex_t *)apr_palloc(pool,
                                                    sizeof(apr_proc_mutex_t));
@@ -259,3 +282,10 @@ APR_DECLARE(apr_status_t) apr_os_proc_mu
     return APR_SUCCESS;
 }
 
+APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
+                                                apr_os_proc_mutex_t *ospmutex,
+                                                apr_pool_t *pool)
+{
+    return apr_os_proc_mutex_put_ex(pmutex, ospmutex, APR_LOCK_DEFAULT_TIMED, pool);
+}
+



Re: svn commit: r1733775 - in /apr/apr/trunk: ./ include/ include/arch/unix/ locks/beos/ locks/netware/ locks/os2/ locks/unix/ locks/win32/

Posted by Ruediger Pluem <rp...@apache.org>.

On 03/07/2016 12:53 PM, Yann Ylavic wrote:
> [resend: list's reply policy strikes again :/ ]
> 
> On Mon, Mar 7, 2016 at 12:47 PM, Yann Ylavic <yl...@gmail.com> wrote:
>> On Mon, Mar 7, 2016 at 10:52 AM, Ruediger Pluem <rp...@apache.org> wrote:
>>>
>>> On 03/06/2016 01:19 AM, ylavic@apache.org wrote:
>>>>
>>>>  /* Implement OS-specific accessors defined in apr_portable.h */
>>>>
>>>> -apr_status_t apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
>>>> -                                   apr_proc_mutex_t *pmutex)
>>>> +APR_DECLARE(apr_status_t) apr_os_proc_mutex_get_ex(apr_os_proc_mutex_t *ospmutex,
>>>> +                                                   apr_proc_mutex_t *pmutex,
>>>> +                                                   apr_lockmech_e *mech)
>>>> +{
>>>> +#if 1
>>>> +    /* We need to change apr_os_proc_mutex_t to a pointer type
>>>> +     * to be able to implement this function.
>>>> +     */
>>>> +    return APR_ENOTIMPL;
>>>> +#else
>>>> +    if (!pmutex->mutex) {
>>>> +        return APR_ENOLOCK;
>>>> +    }
>>>> +    *ospmutex = pmutex->mutex->mutex;
>>>> +    if (mech) {
>>>> +        *mech = APR_LOCK_DEFAULT;
>>>> +    }
>>>> +    return APR_SUCCESS;
>>>> +#endif
>>>> +}
>>>> +
>>>> +APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
>>>> +                                                apr_proc_mutex_t *pmutex)
>>>>  {
>>>> -    if (pmutex)
>>>> -        ospmutex = pmutex->mutex->mutex;
>>>> -    return APR_ENOLOCK;
>>>> +    return apr_os_proc_mutex_get_ex(ospmutex, pmutex, NULL);
>>>>  }
>>>
>>> Previously we always returned APR_ENOLOCK now we return always APR_ENOTIMPL and ospmutex will not be set.
>>> Is this correct?
>>
>> The pointer ospmutex is local here, there is no point in changing its
>> value, that won't help the caller :)
>> The issue is that on Netware, apr_os_proc_mutex_t is the native
>> NXMutex_t struct, so we can't really return a copy to the caller with
>> something like "*ospmutex = *pmutex->mutex;" either since it is likely
>> to not work as expected...

Thanks for explaining.

>> That's why I changed to apr_os_proc_mutex_t to NXMutex_t* in the
>> follow up (r1733777), which breaks the API, whereas this commit aims
>> to be backportable to 1.6 (still apr_os_proc_mutex_get() is
>> ENOTIMPLementable...).
>>
>> However I should have leaved (unconditionally) what is done in
>> r1733777 (and in other platforms) wrt ENOLOCK:
>>
>>     if (!pmutex->mutex) {
>>         return APR_ENOLOCK;
>>     }
>> #if 1
>>     /* ... */
>>     return APR_ENOTIMPL;
>> #else
>>     ...
>> #endif
>>
>> Does it work for you if I take care of this when/if backporting (since
>> trunk is already fixed)?

This is fine for me.

Regards

Rüdiger


Re: svn commit: r1733775 - in /apr/apr/trunk: ./ include/ include/arch/unix/ locks/beos/ locks/netware/ locks/os2/ locks/unix/ locks/win32/

Posted by Yann Ylavic <yl...@gmail.com>.
[resend: list's reply policy strikes again :/ ]

On Mon, Mar 7, 2016 at 12:47 PM, Yann Ylavic <yl...@gmail.com> wrote:
> On Mon, Mar 7, 2016 at 10:52 AM, Ruediger Pluem <rp...@apache.org> wrote:
>>
>> On 03/06/2016 01:19 AM, ylavic@apache.org wrote:
>>>
>>>  /* Implement OS-specific accessors defined in apr_portable.h */
>>>
>>> -apr_status_t apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
>>> -                                   apr_proc_mutex_t *pmutex)
>>> +APR_DECLARE(apr_status_t) apr_os_proc_mutex_get_ex(apr_os_proc_mutex_t *ospmutex,
>>> +                                                   apr_proc_mutex_t *pmutex,
>>> +                                                   apr_lockmech_e *mech)
>>> +{
>>> +#if 1
>>> +    /* We need to change apr_os_proc_mutex_t to a pointer type
>>> +     * to be able to implement this function.
>>> +     */
>>> +    return APR_ENOTIMPL;
>>> +#else
>>> +    if (!pmutex->mutex) {
>>> +        return APR_ENOLOCK;
>>> +    }
>>> +    *ospmutex = pmutex->mutex->mutex;
>>> +    if (mech) {
>>> +        *mech = APR_LOCK_DEFAULT;
>>> +    }
>>> +    return APR_SUCCESS;
>>> +#endif
>>> +}
>>> +
>>> +APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
>>> +                                                apr_proc_mutex_t *pmutex)
>>>  {
>>> -    if (pmutex)
>>> -        ospmutex = pmutex->mutex->mutex;
>>> -    return APR_ENOLOCK;
>>> +    return apr_os_proc_mutex_get_ex(ospmutex, pmutex, NULL);
>>>  }
>>
>> Previously we always returned APR_ENOLOCK now we return always APR_ENOTIMPL and ospmutex will not be set.
>> Is this correct?
>
> The pointer ospmutex is local here, there is no point in changing its
> value, that won't help the caller :)
> The issue is that on Netware, apr_os_proc_mutex_t is the native
> NXMutex_t struct, so we can't really return a copy to the caller with
> something like "*ospmutex = *pmutex->mutex;" either since it is likely
> to not work as expected...
> That's why I changed to apr_os_proc_mutex_t to NXMutex_t* in the
> follow up (r1733777), which breaks the API, whereas this commit aims
> to be backportable to 1.6 (still apr_os_proc_mutex_get() is
> ENOTIMPLementable...).
>
> However I should have leaved (unconditionally) what is done in
> r1733777 (and in other platforms) wrt ENOLOCK:
>
>     if (!pmutex->mutex) {
>         return APR_ENOLOCK;
>     }
> #if 1
>     /* ... */
>     return APR_ENOTIMPL;
> #else
>     ...
> #endif
>
> Does it work for you if I take care of this when/if backporting (since
> trunk is already fixed)?
>
>>
>>> Modified: apr/apr/trunk/locks/unix/proc_mutex.c
>>> URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/proc_mutex.c?rev=1733775&r1=1733774&r2=1733775&view=diff
>>> ==============================================================================
>>> --- apr/apr/trunk/locks/unix/proc_mutex.c (original)
>>> +++ apr/apr/trunk/locks/unix/proc_mutex.c Sun Mar  6 00:19:51 2016
>>
>>> @@ -488,16 +504,16 @@ 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->os.pthread_interproc = mmap(NULL, sizeof(proc_pthread_mutex_t),
>>> +                                           PROT_READ | PROT_WRITE, MAP_SHARED,
>>> +                                           fd, 0);
>>> +    if (new_mutex->os.pthread_interproc == MAP_FAILED) {
>>> +        new_mutex->os.pthread_interproc = NULL;
>>> +        rv = errno;
>>>          close(fd);
>>> -        return errno;
>>> +        return rv;
>>>      }
>>> -    close(fd);
>>
>> Why don't we close the fd any longer?
>
> Good catch! Not really intentional...
> Will fix.
>
> Thanks for the review Rüdiger.
>
> Regards,
> Yann.

Re: svn commit: r1733775 - in /apr/apr/trunk: ./ include/ include/arch/unix/ locks/beos/ locks/netware/ locks/os2/ locks/unix/ locks/win32/

Posted by Ruediger Pluem <rp...@apache.org>.

On 03/06/2016 01:19 AM, ylavic@apache.org wrote:
> Author: ylavic
> Date: Sun Mar  6 00:19:51 2016
> New Revision: 1733775
> 
> URL: http://svn.apache.org/viewvc?rev=1733775&view=rev
> Log:
> apr_proc/global_mutex: Fix API regarding the native OS mutexes
> accessors from/to available APR mechanisms, adding the new functions
> apr_os_proc_mutex_get_ex() and apr_os_proc_mutex_set_ex() which give
> control to the user over the selected mechanisms, including the missing
> POSIX semaphores (sem_t) on platforms supporting them.
> 
> For POSIX sems, this moves the "sem_t *psem_interproc;" member from struct
> apr_proc_mutex_t to apr_os_proc_mutex_t (now complete) so that we can avoid
> members duplication between the two structs, and hence replace all the doublons
> in apr_os_proc_mutex_t with an apr_os_proc_mutex_t member, called "os", to be
> used for runtime.
> 
> This first commit aims to be backportable to 1.6.x, thus does not address the
> Netware case which requires an incompatible change of the apr_proc_mutex_t to
> a pointer type (the implementation is here since very similar to other changes
> is this commit, but it is commented out for now, a simple follow up is coming
> with the type change for trunk only...).
>  
> 
> Modified:
>     apr/apr/trunk/CHANGES
>     apr/apr/trunk/include/apr_global_mutex.h
>     apr/apr/trunk/include/apr_portable.h
>     apr/apr/trunk/include/apr_proc_mutex.h
>     apr/apr/trunk/include/arch/unix/apr_arch_proc_mutex.h
>     apr/apr/trunk/locks/beos/proc_mutex.c
>     apr/apr/trunk/locks/netware/proc_mutex.c
>     apr/apr/trunk/locks/os2/proc_mutex.c
>     apr/apr/trunk/locks/unix/global_mutex.c
>     apr/apr/trunk/locks/unix/proc_mutex.c
>     apr/apr/trunk/locks/win32/proc_mutex.c
> 

> Modified: apr/apr/trunk/locks/netware/proc_mutex.c
> URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/netware/proc_mutex.c?rev=1733775&r1=1733774&r2=1733775&view=diff
> ==============================================================================
> --- apr/apr/trunk/locks/netware/proc_mutex.c (original)
> +++ apr/apr/trunk/locks/netware/proc_mutex.c Sun Mar  6 00:19:51 2016

> @@ -121,18 +126,65 @@ APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
>  
>  /* Implement OS-specific accessors defined in apr_portable.h */
>  
> -apr_status_t apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
> -                                   apr_proc_mutex_t *pmutex)
> +APR_DECLARE(apr_status_t) apr_os_proc_mutex_get_ex(apr_os_proc_mutex_t *ospmutex, 
> +                                                   apr_proc_mutex_t *pmutex,
> +                                                   apr_lockmech_e *mech)
> +{
> +#if 1
> +    /* We need to change apr_os_proc_mutex_t to a pointer type
> +     * to be able to implement this function.
> +     */
> +    return APR_ENOTIMPL;
> +#else
> +    if (!pmutex->mutex) {
> +        return APR_ENOLOCK;
> +    }
> +    *ospmutex = pmutex->mutex->mutex;
> +    if (mech) {
> +        *mech = APR_LOCK_DEFAULT;
> +    }
> +    return APR_SUCCESS;
> +#endif
> +}
> +
> +APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
> +                                                apr_proc_mutex_t *pmutex)
>  {
> -    if (pmutex)
> -        ospmutex = pmutex->mutex->mutex;
> -    return APR_ENOLOCK;
> +    return apr_os_proc_mutex_get_ex(ospmutex, pmutex, NULL);
>  }

Previously we always returned APR_ENOLOCK now we return always APR_ENOTIMPL and ospmutex will not be set.
Is this correct?

> Modified: apr/apr/trunk/locks/unix/proc_mutex.c
> URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/proc_mutex.c?rev=1733775&r1=1733774&r2=1733775&view=diff
> ==============================================================================
> --- apr/apr/trunk/locks/unix/proc_mutex.c (original)
> +++ apr/apr/trunk/locks/unix/proc_mutex.c Sun Mar  6 00:19:51 2016

> @@ -488,16 +504,16 @@ 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->os.pthread_interproc = mmap(NULL, sizeof(proc_pthread_mutex_t),
> +                                           PROT_READ | PROT_WRITE, MAP_SHARED,
> +                                           fd, 0); 
> +    if (new_mutex->os.pthread_interproc == MAP_FAILED) {
> +        new_mutex->os.pthread_interproc = NULL;
> +        rv = errno;
>          close(fd);
> -        return errno;
> +        return rv;
>      }
> -    close(fd);

Why don't we close the fd any longer?

> +    new_mutex->pthread_refcounting = 1;
>  
>      new_mutex->curr_locked = -1; /* until the mutex has been created */
>  

Regards

Rüdiger