summaryrefslogtreecommitdiff
path: root/locks
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2016-03-06 00:19:51 +0000
committerYann Ylavic <ylavic@apache.org>2016-03-06 00:19:51 +0000
commit4374120da1da5fefd2a1865868a698cc416f83c3 (patch)
tree976669566fec3c84f71506cbd1797ee26f8ab426 /locks
parentace1569206bf502316ad17a0514b9c25daca59f1 (diff)
downloadapr-4374120da1da5fefd2a1865868a698cc416f83c3.tar.gz
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...). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1733775 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks')
-rw-r--r--locks/beos/proc_mutex.c32
-rw-r--r--locks/netware/proc_mutex.c68
-rw-r--r--locks/os2/proc_mutex.c37
-rw-r--r--locks/unix/global_mutex.c9
-rw-r--r--locks/unix/proc_mutex.c347
-rw-r--r--locks/win32/proc_mutex.c36
6 files changed, 405 insertions, 124 deletions
diff --git a/locks/beos/proc_mutex.c b/locks/beos/proc_mutex.c
index 4408df094..d5c681741 100644
--- a/locks/beos/proc_mutex.c
+++ b/locks/beos/proc_mutex.c
@@ -182,6 +182,11 @@ APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *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_mutex_put(apr_proc_mutex_t **pmutex,
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);
+}
+
diff --git a/locks/netware/proc_mutex.c b/locks/netware/proc_mutex.c
index 4217b1cf0..04b7672f9 100644
--- a/locks/netware/proc_mutex.c
+++ b/locks/netware/proc_mutex.c
@@ -105,6 +105,11 @@ APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *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 (pmutex)
- ospmutex = pmutex->mutex->mutex;
- return APR_ENOLOCK;
+#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)
+{
+ 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);
}
diff --git a/locks/os2/proc_mutex.c b/locks/os2/proc_mutex.c
index e873963f2..83f64c848 100644
--- a/locks/os2/proc_mutex.c
+++ b/locks/os2/proc_mutex.c
@@ -60,6 +60,11 @@ APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *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_mutex_put(apr_proc_mutex_t **pmutex,
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);
+}
+
diff --git a/locks/unix/global_mutex.c b/locks/unix/global_mutex.c
index 19485c487..b343e23ad 100644
--- a/locks/unix/global_mutex.c
+++ b/locks/unix/global_mutex.c
@@ -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_mutex_create(apr_global_mutex_t **mutex,
}
#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_mutex_lockfile(apr_global_mutex_t *mutex)
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)
+
diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c
index 9325c2114..9b623c6bc 100644
--- a/locks/unix/proc_mutex.c
+++ b/locks/unix/proc_mutex.c
@@ -57,7 +57,7 @@ static apr_status_t proc_mutex_posix_cleanup(void *mutex_)
{
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_create(apr_proc_mutex_t *new_mutex,
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_create(apr_proc_mutex_t *new_mutex,
}
/* 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_acquire(apr_proc_mutex_t *mutex)
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_tryacquire(apr_proc_mutex_t *mutex)
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_timedacquire(apr_proc_mutex_t *mutex,
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_timedacquire(apr_proc_mutex_t *mutex,
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_methods_t mutex_posixsem_methods =
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_cleanup(void *mutex_)
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_create(apr_proc_mutex_t *new_mutex,
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_acquire(apr_proc_mutex_t *mutex)
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_tryacquire(apr_proc_mutex_t *mutex)
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_timedacquire(apr_proc_mutex_t *mutex,
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_release(apr_proc_mutex_t *mutex)
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_perms_set(apr_proc_mutex_t *mutex,
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_methods_t mutex_sysv_methods =
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_unref(void *mutex_)
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_pthread_cleanup(void *mutex_)
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_pthread_create(apr_proc_mutex_t *new_mutex,
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_pthread_create(apr_proc_mutex_t *new_mutex,
}
#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_pthread_child_init(apr_proc_mutex_t **mutex,
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_pthread_acquire(apr_proc_mutex_t *mutex)
{
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_pthread_tryacquire(apr_proc_mutex_t *mutex)
{
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_pthread_tryacquire(apr_proc_mutex_t *mutex)
#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_proc_mutex_t *mutex,
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_proc_mutex_t *mutex,
#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_pthread_release(apr_proc_mutex_t *mutex)
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_methods_t mutex_proc_pthread_methods =
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_cleanup(void *mutex_)
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_create(apr_proc_mutex_t *new_mutex,
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_acquire(apr_proc_mutex_t *mutex)
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_tryacquire(apr_proc_mutex_t *mutex)
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_release(apr_proc_mutex_t *mutex)
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_perms_set(apr_proc_mutex_t *mutex,
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_methods_t mutex_fcntl_methods =
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_release(apr_proc_mutex_t *);
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_cleanup(void *mutex_)
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_create(apr_proc_mutex_t *new_mutex,
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_acquire(apr_proc_mutex_t *mutex)
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_tryacquire(apr_proc_mutex_t *mutex)
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_release(apr_proc_mutex_t *mutex)
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_child_init(apr_proc_mutex_t **mutex,
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_perms_set(apr_proc_mutex_t *mutex,
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_methods_t mutex_flock_methods =
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_method(apr_proc_mutex_t *new_mutex, apr_lo
#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_defname(void)
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(apr_proc_mutex_t *new_mutex, apr_lockmech_
{
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_cleanup(void *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(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 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;
+ *ospmutex = pmutex->os;
+ if (mech) {
+ *mech = pmutex->meth->mech;
}
-#endif
-#if APR_HAS_PROC_PTHREAD_SERIALIZE
- ospmutex->pthread_interproc = pmutex->pthread_interproc;
-#endif
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)
{
+ apr_status_t rv;
if (pool == NULL) {
return APR_ENOPOOL;
}
@@ -1243,12 +1374,20 @@ APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
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);
}
diff --git a/locks/win32/proc_mutex.c b/locks/win32/proc_mutex.c
index 5ec9b2648..83042ce35 100644
--- a/locks/win32/proc_mutex.c
+++ b/locks/win32/proc_mutex.c
@@ -43,6 +43,10 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **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_lockfile(apr_proc_mutex_t *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_mutex_put(apr_proc_mutex_t **pmutex,
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);
+}
+