summaryrefslogtreecommitdiff
path: root/locks
diff options
context:
space:
mode:
authoraaron <aaron@13f79535-47bb-0310-9956-ffa450edef68>2002-04-09 06:56:56 +0000
committeraaron <aaron@13f79535-47bb-0310-9956-ffa450edef68>2002-04-09 06:56:56 +0000
commit5012b3e8eb1ee9929aecad60a9c9ac440dd75f57 (patch)
tree7e9b75de87328965023c39fdb1e7e7abc9fff77f /locks
parent7175e52e6224f552dc90ff091b42a11d378c14cb (diff)
downloadlibapr-5012b3e8eb1ee9929aecad60a9c9ac440dd75f57.tar.gz
** DEPRECATE old lock API: apr_lock.h **
Resolve some circular includes (apr_thread_mutex.h needs apr_pools.h needs apr_allocator.h needs apr_thread_mutex.h ...). Remove all apr_lock.h related files (incl. arch-specific headers and implementations). git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@63234 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks')
-rw-r--r--locks/beos/locks.c459
-rw-r--r--locks/netware/locks.c317
-rw-r--r--locks/os2/locks.c288
-rw-r--r--locks/unix/Makefile.in3
-rw-r--r--locks/unix/crossproc.c738
-rw-r--r--locks/unix/intraproc.c229
-rw-r--r--locks/unix/locks.c412
-rw-r--r--locks/unix/proc_mutex.c6
-rw-r--r--locks/win32/locks.c303
9 files changed, 2 insertions, 2753 deletions
diff --git a/locks/beos/locks.c b/locks/beos/locks.c
deleted file mode 100644
index 4ac75cf96..000000000
--- a/locks/beos/locks.c
+++ /dev/null
@@ -1,459 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-/*Read/Write locking implementation based on the MultiLock code from
- * Stephen Beaulieu <hippo@be.com>
- */
-
-#include "beos/locks.h"
-#include "apr_strings.h"
-#include "apr_portable.h"
-
-#define BIG_NUM 100000
-
-static apr_status_t _lock_cleanup(void * data)
-{
- apr_lock_t *lock = (apr_lock_t*)data;
- if (lock->LockCount != 0) {
- /* we're still locked... */
- while (atomic_add(&lock->LockCount , -1) > 1){
- /* OK we had more than one person waiting on the lock so
- * the sem is also locked. Release it until we have no more
- * locks left.
- */
- release_sem (lock->Lock);
- }
- }
- delete_sem(lock->Lock);
- return APR_SUCCESS;
-}
-
-static apr_status_t _lock_rw_cleanup(void * data)
-{
- apr_lock_t *lock = (apr_lock_t*)data;
-
- if (lock->ReadCount != 0) {
- while (atomic_add(&lock->ReadCount , -1) > 1){
- release_sem (lock->Read);
- }
- }
- if (lock->WriteCount != 0) {
- while (atomic_add(&lock->WriteCount , -1) > 1){
- release_sem (lock->Write);
- }
- }
- if (lock->LockCount != 0) {
- while (atomic_add(&lock->LockCount , -1) > 1){
- release_sem (lock->Lock);
- }
- }
-
- delete_sem(lock->Read);
- delete_sem(lock->Write);
- delete_sem(lock->Lock);
- return APR_SUCCESS;
-}
-
-static apr_status_t _create_lock(apr_lock_t *new)
-{
- int32 stat;
-
- if ((stat = create_sem(0, "APR_Lock")) < B_NO_ERROR) {
- _lock_cleanup(new);
- return stat;
- }
- new->LockCount = 0;
- new->Lock = stat;
- apr_pool_cleanup_register(new->pool, (void *)new, _lock_cleanup,
- apr_pool_cleanup_null);
- return APR_SUCCESS;
-}
-
-static apr_status_t _create_rw_lock(apr_lock_t *new)
-{
- /* we need to make 3 locks... */
- new->ReadCount = 0;
- new->WriteCount = 0;
- new->LockCount = 0;
- new->Read = create_sem(0, "APR_ReadLock");
- new->Write = create_sem(0, "APR_WriteLock");
- new->Lock = create_sem(0, "APR_Lock");
-
- if (new->Lock < 0 || new->Read < 0 || new->Write < 0) {
- _lock_rw_cleanup(new);
- return -1;
- }
-
- apr_pool_cleanup_register(new->pool, (void *)new, _lock_rw_cleanup,
- apr_pool_cleanup_null);
- return APR_SUCCESS;
-}
-
-static apr_status_t _lock(apr_lock_t *lock)
-{
- int32 stat;
-
- if (atomic_add(&lock->LockCount, 1) > 0) {
- if ((stat = acquire_sem(lock->Lock)) < B_NO_ERROR) {
- atomic_add(&lock->LockCount, -1);
- return stat;
- }
- }
- return APR_SUCCESS;
-}
-
-static apr_status_t _unlock(apr_lock_t *lock)
-{
- int32 stat;
-
- if (atomic_add(&lock->LockCount, -1) > 1) {
- if ((stat = release_sem(lock->Lock)) < B_NO_ERROR) {
- atomic_add(&lock->LockCount, 1);
- return stat;
- }
- }
- return APR_SUCCESS;
-}
-
-static apr_status_t _read_lock(apr_lock_t *lock)
-{
- int32 rv = APR_SUCCESS;
-
- if (find_thread(NULL) == lock->writer) {
- /* we're the writer - no problem */
- lock->Nested++;
- } else {
- /* we're not the writer */
- int32 r = atomic_add(&lock->ReadCount, 1);
- if (r < 0) {
- /* Oh dear, writer holds lock, wait for sem */
- rv = acquire_sem_etc(lock->Read, 1, B_DO_NOT_RESCHEDULE,
- B_INFINITE_TIMEOUT);
- }
- }
-
- return rv;
-}
-
-static apr_status_t _write_lock(apr_lock_t *lock)
-{
- int rv = APR_SUCCESS;
-
- if (find_thread(NULL) == lock->writer) {
- lock->Nested++;
- } else {
- /* we're not the writer... */
- if (atomic_add(&lock->LockCount, 1) >= 1) {
- /* we're locked - acquire the sem */
- rv = acquire_sem_etc(lock->Lock, 1, B_DO_NOT_RESCHEDULE,
- B_INFINITE_TIMEOUT);
- }
- if (rv == APR_SUCCESS) {
- /* decrement the ReadCount to a large -ve number so that
- * we block on new readers...
- */
- int32 readers = atomic_add(&lock->ReadCount, -BIG_NUM);
- if (readers > 0) {
- /* readers are holding the lock */
- rv = acquire_sem_etc(lock->Write, readers, B_DO_NOT_RESCHEDULE,
- B_INFINITE_TIMEOUT);
- }
- if (rv == APR_SUCCESS)
- lock->writer = find_thread(NULL);
- }
- }
-
- return rv;
-}
-
-
-static apr_status_t _read_unlock(apr_lock_t *lock)
-{
- apr_status_t rv = APR_SUCCESS;
-
- /* we know we hold the lock, so don't check it :) */
- if (find_thread(NULL) == lock->writer) {
- /* we're recursively locked */
- lock->Nested--;
- return APR_SUCCESS;
- }
- /* OK so we need to release the sem if we have it :) */
- if (atomic_add(&lock->ReadCount, -1) < 0) {
- /* we have a writer waiting for the lock, so release it */
- rv = release_sem_etc(lock->Write, 1, B_DO_NOT_RESCHEDULE);
- }
-
- return rv;
-}
-
-static apr_status_t _write_unlock(apr_lock_t *lock)
-{
- apr_status_t rv = APR_SUCCESS;
- int32 readers;
-
- /* we know we hold the lock, so don't check it :) */
- if (lock->Nested > 1) {
- /* we're recursively locked */
- lock->Nested--;
- return APR_SUCCESS;
- }
- /* OK so we need to release the sem if we have it :) */
- readers = atomic_add(&lock->ReadCount, BIG_NUM) + BIG_NUM;
- if (readers > 0) {
- rv = release_sem_etc(lock->Read, readers, B_DO_NOT_RESCHEDULE);
- }
- if (rv == APR_SUCCESS) {
- lock->writer = -1;
- if (atomic_add(&lock->LockCount, -1) > 1) {
- rv = release_sem_etc(lock->Lock, 1, B_DO_NOT_RESCHEDULE);
- }
- }
-
- return rv;
-}
-
-static apr_status_t _destroy_lock(apr_lock_t *lock)
-{
- apr_status_t stat;
- if ((stat = _lock_cleanup(lock)) == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->pool, lock, _lock_cleanup);
- return APR_SUCCESS;
- }
- return stat;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_create(apr_lock_t **lock, apr_locktype_e type,
- apr_lockscope_e scope, apr_lockmech_e mech,
- const char *fname, apr_pool_t *pool)
-{
- apr_lock_t *new;
- apr_status_t stat = APR_SUCCESS;
-
- if (mech != APR_LOCK_DEFAULT) {
- return APR_ENOTIMPL;
- }
-
- new = (apr_lock_t *)apr_pcalloc(pool, sizeof(apr_lock_t));
- if (new == NULL){
- return APR_ENOMEM;
- }
-
- new->pool = pool;
- new->type = type;
- new->scope = scope;
-
- if (type == APR_MUTEX) {
- stat = _create_lock(new);
- } else if (type == APR_READWRITE) {
- stat = _create_rw_lock(new);
- }
-
- if (stat != APR_SUCCESS)
- return stat;
-
- (*lock) = new;
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_acquire(apr_lock_t *lock)
-{
- apr_status_t stat;
-
- if (lock->owner == apr_os_thread_current()) {
- lock->owner_ref++;
- return APR_SUCCESS;
- }
-
- switch (lock->type)
- {
- case APR_MUTEX:
- if ((stat = _lock(lock)) != APR_SUCCESS)
- return stat;
- break;
-
- case APR_READWRITE:
- return APR_ENOTIMPL;
- }
-
- lock->owner = apr_os_thread_current();
- lock->owner_ref = 1;
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_tryacquire(apr_lock_t *lock)
-{
- return APR_ENOTIMPL;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_acquire_rw(apr_lock_t *lock, apr_readerwriter_e e)
-{
- switch (lock->type)
- {
- case APR_MUTEX:
- return APR_ENOTIMPL;
- case APR_READWRITE:
- switch (e)
- {
- case APR_READER:
- _read_lock(lock);
- break;
- case APR_WRITER:
- _write_lock(lock);
- break;
- }
- }
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_release(apr_lock_t *lock)
-{
- apr_status_t stat = APR_SUCCESS;
-
- if (lock->owner_ref > 0 && lock->owner == apr_os_thread_current()) {
- lock->owner_ref--;
- if (lock->owner_ref > 0)
- return APR_SUCCESS;
- }
-
- switch (lock->type)
- {
- case APR_MUTEX:
- stat = _unlock(lock);
- break;
- case APR_READWRITE:
- {
- thread_id me = find_thread(NULL);
- if (me == lock->writer)
- stat = _write_unlock(lock);
- else
- stat = _read_unlock(lock);
- }
- /* if we don't hold the read or write lock then why are
- * we calling release???
- *
- * Just return success.
- */
- break;
- }
-
- if (stat != APR_SUCCESS)
- return stat;
-
- lock->owner = -1;
- lock->owner_ref = 0;
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_destroy(apr_lock_t *lock)
-{
- apr_status_t stat;
-
- switch (lock->type)
- {
- case APR_MUTEX:
- if ((stat = _destroy_lock(lock)) != APR_SUCCESS)
- return stat;
- break;
- case APR_READWRITE:
- return APR_ENOTIMPL;
- }
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_child_init(apr_lock_t **lock, const char *fname,
- apr_pool_t *pool)
-{
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_data_get(apr_lock_t *lock,
- const char *key, void *data)
-{
- return apr_pool_userdata_get(data, key, lock->pool);
-}
-
-APR_DECLARE(apr_status_t) apr_lock_data_set(apr_lock_t *lock,
- void *data, const char *key,
- apr_status_t (*cleanup) (void *))
-{
- return apr_pool_userdata_set(data, key, cleanup, lock->pool);
-}
-
-APR_DECLARE(apr_status_t) apr_os_lock_get(apr_os_lock_t *oslock, apr_lock_t *lock)
-{
- oslock->sem = lock->Lock;
- oslock->ben = lock->LockCount;
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_os_lock_put(apr_lock_t **lock, apr_os_lock_t *thelock,
- apr_pool_t *pool)
-{
- if (pool == NULL) {
- return APR_ENOPOOL;
- }
- if ((*lock) == NULL) {
- (*lock) = (apr_lock_t *)apr_pcalloc(pool, sizeof(apr_lock_t));
- (*lock)->pool = pool;
- }
- (*lock)->Lock = thelock->sem;
- (*lock)->LockCount = thelock->ben;
-
- return APR_SUCCESS;
-}
-
diff --git a/locks/netware/locks.c b/locks/netware/locks.c
deleted file mode 100644
index b7aa2a764..000000000
--- a/locks/netware/locks.c
+++ /dev/null
@@ -1,317 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-#include "apr.h"
-#include "apr_private.h"
-#include "apr_general.h"
-#include "apr_strings.h"
-#include "locks.h"
-#include "apr_portable.h"
-
-static apr_status_t lock_cleanup(void *lock_)
-{
- apr_lock_t *lock = lock_;
-
- switch (lock->type)
- {
- case APR_MUTEX:
- NXMutexFree(lock->mutex);
- break;
- case APR_READWRITE:
- NXRwLockFree (lock->rwlock);
- break;
- }
- return APR_SUCCESS;
-}
-
-apr_status_t apr_lock_create(apr_lock_t **lock, apr_locktype_e type, apr_lockscope_e scope,
- apr_lockmech_e mech, const char *fname, apr_pool_t *pool)
-{
-
- apr_lock_t *newlock = NULL;
-
- /* struct apr_lock_t {
- apr_pool_t *pool;
- apr_locktype_e type;
- apr_lockscope_e scope;
- NXMutex_t *mutex;
- NXRwLock_t *rwlock;
- char *fname;
- };
- */
- NXHierarchy_t hierarchy=0; //for libc NKS NXRwLockAlloc
- NXLockInfo_t *info; //for libc NKS NXRwLockAlloc
- apr_status_t status;
- long flags = 0;
-
- if (mech != APR_LOCK_DEFAULT) {
- return APR_ENOTIMPL;
- }
-
- newlock = (apr_lock_t *)apr_palloc(pool, sizeof(apr_lock_t));
-
- if(newlock ==NULL) {
- return APR_ENOMEM;
- }
- newlock->pool = pool;
- /* ToDo: How to handle the case when no pool is available?
- * How to cleanup the storage properly?
- */
- newlock->fname = apr_pstrdup(pool, fname);
- newlock->type = type;
- newlock->scope = scope;
-
-//srj fill in scope later
-//srj if (scope == APR_INTRAPROCESS) {
-//srj InitializeCriticalSection(&newlock->section);
-//srj } else {
-
- switch (type)
- {
- case APR_MUTEX:
- flags=NX_MUTEX_RECURSIVE;
- newlock->mutex = NXMutexAlloc(flags,NULL, NULL);
-
- if(newlock->mutex == NULL)
- return APR_ENOMEM;
- break;
- case APR_READWRITE:
-
- info = (NXLockInfo_t *)apr_palloc(pool, sizeof(NXLockInfo_t));
- hierarchy=1;
- //srj NXRwLockAlloc Allocates and initializes a reader/writer lock
- //srj RWLocks are not recursive
- newlock->rwlock = NXRwLockAlloc(hierarchy,info);
- if(newlock->rwlock == NULL)
- return APR_ENOMEM;
- break;
- }
-
-// } end of else for scope
-
- *lock = newlock;
- apr_pool_cleanup_register(newlock->pool, newlock, lock_cleanup,
- apr_pool_cleanup_null);
- return APR_SUCCESS;
-}
-
-apr_status_t apr_lock_child_init(apr_lock_t **lock,
- const char *fname,
- apr_pool_t *pool)
-{
- /* This routine should not be called ( OpenMutex will fail if called)
- * on a INTRAPROCESS lock
- */
- (*lock) = (apr_lock_t *)apr_palloc(pool, sizeof(apr_lock_t));
-
- if ((*lock) == NULL) {
- return APR_ENOMEM;
- }
- (*lock)->fname = apr_pstrdup(pool, fname);
-
- if ((*lock)->mutex == NULL) {
- return apr_get_os_error();
- }
- return APR_SUCCESS;
-}
-
-apr_status_t apr_lock_acquire(apr_lock_t *lock)
-{
- DWORD rv;
- switch (lock->type)
- {
- case APR_MUTEX:
- if(NXLock(lock->mutex)==0)
- return APR_SUCCESS;
- break;
- //srj APR_READWRITE should not be called here. Not Needed
- //srj since we have apr_lock_acquire_rw function
-
- case APR_READWRITE:
- return APR_ENOTIMPL;
- default:
- return APR_EINVAL;
- }
-
- return apr_get_os_error();
-}
-
-APR_DECLARE(apr_status_t) apr_lock_tryacquire(apr_lock_t *lock)
-{
- return APR_ENOTIMPL;
-}
-
-apr_status_t apr_lock_acquire_rw(apr_lock_t *lock,
- apr_readerwriter_e e)
-{
- switch (lock->type)
- {
- case APR_MUTEX:
- return APR_ENOTIMPL;
-
- case APR_READWRITE:
-
- switch (e)
- {
- case APR_READER:
-#if 0
- //srj NXRdLock specifies the reader/writer lock in the read mode
- //No return values
- NXRdLock (lock->rwlock);
-#endif
- break;
- case APR_WRITER:
-#if 0
- //srj NXWrLock specifies the reader/writer lock in the write mode
- //No return values
- NXWrLock (lock->rwlock);
-#endif
- break;
- }
-
- default:
- return APR_EINVAL;
- }
-
- return APR_SUCCESS;
-}
-
-apr_status_t apr_lock_release(apr_lock_t *lock)
-{
- switch (lock->type)
- {
- case APR_MUTEX:
-//srj will work on scope later
-//
-// if (lock->scope == APR_INTRAPROCESS) {
-// LeaveCriticalSection(&lock->section);
-// return APR_SUCCESS;
-// } else {
- if(NXUnlock(lock->mutex)==0);
- return APR_SUCCESS;
-// }
- break;
-
- case APR_READWRITE:
- return APR_ENOTIMPL;
- /*NXRwUnlock (lock->rwlock);*/
- }
-
- return apr_get_os_error();
-}
-
-apr_status_t apr_lock_destroy(apr_lock_t *lock)
-{
- apr_status_t stat;
-
- stat = lock_cleanup(lock);
- if (stat == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->pool, lock, lock_cleanup);
- }
- return stat;
-}
-
-apr_status_t apr_lock_data_get(apr_lock_t *lock, const char *key,
- void *data)
-{
- return apr_pool_userdata_get(data, key, lock->pool);
-}
-
-apr_status_t apr_lock_data_set(apr_lock_t *lock, void *data,
- const char *key,
- apr_status_t (*cleanup) (void *))
-{
- return apr_pool_userdata_set(data, key, cleanup, lock->pool);
-}
-
-apr_status_t apr_os_lock_get(apr_os_lock_t *thelock,
- apr_lock_t *lock)
-{
- switch (lock->type)
- {
- case APR_MUTEX:
- thelock = lock->mutex;
- break;
- case APR_READWRITE:
- return APR_ENOTIMPL;
- /* thelock = lock->rwlock;*/
- break;
- }
-
- return APR_SUCCESS;
-}
-
-apr_status_t apr_os_lock_put(apr_lock_t **lock,
- apr_os_lock_t *thelock,
- apr_pool_t *pool)
-{
- if (pool == NULL) {
- return APR_ENOPOOL;
- }
- if ((*lock) == NULL) {
- (*lock) = (apr_lock_t *)apr_palloc(pool, sizeof(apr_lock_t));
- (*lock)->pool = pool;
- }
- switch ((*lock)->type)
- {
- case APR_MUTEX:
- (*lock)->mutex = thelock;
- break;
- case APR_READWRITE:
- return APR_ENOTIMPL;
- /*(*lock)->rwlock = *thelock;*/
- break;
- }
- return APR_SUCCESS;
-}
diff --git a/locks/os2/locks.c b/locks/os2/locks.c
deleted file mode 100644
index 222a8e6f5..000000000
--- a/locks/os2/locks.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-#include "apr_general.h"
-#include "apr_lib.h"
-#include "apr_strings.h"
-#include "apr_portable.h"
-#include "locks.h"
-#include "fileio.h"
-#include <string.h>
-
-#define CurrentTid (lock->tib->tib_ptib2->tib2_ultid)
-
-
-static apr_status_t lock_cleanup(void *thelock)
-{
- apr_lock_t *lock = thelock;
- return apr_lock_destroy(lock);
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_lock_create(apr_lock_t **lock, apr_locktype_e type,
- apr_lockscope_e scope, apr_lockmech_e mech,
- const char *fname, apr_pool_t *pool)
-{
- apr_lock_t *new;
- ULONG rc;
- char *semname;
- PIB *ppib;
-
- /* FIXME: Remove when read write locks implemented. */
- if (type == APR_READWRITE)
- return APR_ENOTIMPL;
-
- if (mech != APR_LOCK_DEFAULT) {
- return APR_ENOTIMPL;
- }
-
- new = (apr_lock_t *)apr_palloc(pool, sizeof(apr_lock_t));
-
- new->pool = pool;
- new->type = type;
- new->scope = scope;
- new->owner = 0;
- new->lock_count = 0;
- new->fname = apr_pstrdup(pool, fname);
-
- DosGetInfoBlocks(&(new->tib), &ppib);
-
- if (fname == NULL)
- semname = NULL;
- else
- semname = apr_pstrcat(pool, "/SEM32/", fname, NULL);
-
- rc = DosCreateMutexSem(semname, &(new->hMutex), scope == APR_CROSS_PROCESS ? DC_SEM_SHARED : 0, FALSE);
- *lock = new;
-
- if (!rc)
- apr_pool_cleanup_register(pool, new, lock_cleanup, apr_pool_cleanup_null);
-
- return APR_OS2_STATUS(rc);
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_lock_child_init(apr_lock_t **lock, const char *fname,
- apr_pool_t *pool)
-{
- int rc;
- PIB *ppib;
-
- *lock = (apr_lock_t *)apr_palloc(pool, sizeof(apr_lock_t));
-
- if (lock == NULL)
- return APR_ENOMEM;
-
- DosGetInfoBlocks(&((*lock)->tib), &ppib);
- (*lock)->owner = 0;
- (*lock)->lock_count = 0;
- rc = DosOpenMutexSem( (char *)fname, &(*lock)->hMutex );
-
- if (!rc)
- apr_pool_cleanup_register(pool, *lock, lock_cleanup, apr_pool_cleanup_null);
-
- return APR_OS2_STATUS(rc);
-}
-
-
-
-// blocks for no more than ms_timeout milliseconds
-static apr_status_t os2_lock_acquire(apr_lock_t *lock, int ms_timeout)
-{
- ULONG rc;
-
- switch (lock->type) {
- case APR_MUTEX:
- rc = DosRequestMutexSem(lock->hMutex, ms_timeout);
-
- if (rc == 0) {
- lock->owner = CurrentTid;
- lock->lock_count++;
- }
- break;
- case APR_READWRITE:
- return APR_ENOTIMPL;
- default:
- return APR_EINVAL;
- }
-
- return APR_OS2_STATUS(rc);
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_lock_acquire(apr_lock_t *lock)
-{
- return os2_lock_acquire(lock, SEM_INDEFINITE_WAIT);
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_lock_tryacquire(apr_lock_t *lock)
-{
- return os2_lock_acquire(lock, SEM_IMMEDIATE_RETURN);
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_lock_acquire_rw(apr_lock_t *lock, apr_readerwriter_e e)
-{
- switch (lock->type) {
- case APR_MUTEX:
- return APR_ENOTIMPL;
- case APR_READWRITE:
- switch (e) {
- case APR_READER:
- break;
- case APR_WRITER:
- break;
- }
- return APR_ENOTIMPL;
- }
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_release(apr_lock_t *lock)
-{
- ULONG rc;
-
- switch (lock->type) {
- case APR_MUTEX:
- if (lock->owner == CurrentTid && lock->lock_count > 0) {
- lock->lock_count--;
- rc = DosReleaseMutexSem(lock->hMutex);
- return APR_OS2_STATUS(rc);
- }
- break;
- case APR_READWRITE:
- return APR_ENOTIMPL;
- }
-
- return APR_SUCCESS;
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_lock_destroy(apr_lock_t *lock)
-{
- ULONG rc;
- apr_status_t stat = APR_SUCCESS;
-
- switch (lock->type) {
- case APR_MUTEX:
- if (lock->owner == CurrentTid) {
- while (lock->lock_count > 0 && stat == APR_SUCCESS)
- stat = apr_lock_release(lock);
- }
-
- if (stat != APR_SUCCESS)
- return stat;
-
- if (lock->hMutex == 0)
- return APR_SUCCESS;
-
- rc = DosCloseMutexSem(lock->hMutex);
-
- if (!rc)
- lock->hMutex = 0;
- break;
- case APR_READWRITE:
- return APR_ENOTIMPL;
- default:
- return APR_EINVAL;
- }
-
- return APR_OS2_STATUS(rc);
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_os_lock_get(apr_os_lock_t *oslock, apr_lock_t *lock)
-{
- *oslock = lock->hMutex;
- return APR_SUCCESS;
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_os_lock_put(apr_lock_t **lock, apr_os_lock_t *thelock,
- apr_pool_t *pool)
-{
- if (pool == NULL) {
- return APR_ENOPOOL;
- }
- if ((*lock) == NULL) {
- (*lock) = (apr_lock_t *)apr_pcalloc(pool, sizeof(apr_lock_t));
- (*lock)->pool = pool;
- }
- (*lock)->hMutex = *thelock;
- return APR_SUCCESS;
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_lock_data_get(apr_lock_t *lock, const char *key, void *data)
-{
- return apr_pool_userdata_get(data, key, lock->pool);
-}
-
-
-
-APR_DECLARE(apr_status_t) apr_lock_data_set(apr_lock_t *lock, void *data, const char *key,
- apr_status_t (*cleanup) (void *))
-{
- return apr_pool_userdata_set(data, key, cleanup, lock->pool);
-}
diff --git a/locks/unix/Makefile.in b/locks/unix/Makefile.in
index 2ca8f735d..ab1b91d92 100644
--- a/locks/unix/Makefile.in
+++ b/locks/unix/Makefile.in
@@ -1,8 +1,5 @@
TARGETS = \
- locks.lo \
- crossproc.lo \
- intraproc.lo \
thread_mutex.lo \
thread_rwlock.lo \
thread_cond.lo \
diff --git a/locks/unix/crossproc.c b/locks/unix/crossproc.c
deleted file mode 100644
index 78af3f1c5..000000000
--- a/locks/unix/crossproc.c
+++ /dev/null
@@ -1,738 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-#include "apr.h"
-#include "apr_file_io.h"
-#include "apr_strings.h"
-#include "locks.h"
-#include "fileio.h" /* for apr_mkstemp() */
-
-#if APR_HAS_POSIXSEM_SERIALIZE
-
-#ifndef SEM_FAILED
-#define SEM_FAILED (-1)
-#endif
-
-static void posix_setup(void)
-{
-}
-
-static apr_status_t posix_cleanup(void *lock_)
-{
- apr_lock_t *lock=lock_;
- apr_status_t stat = APR_SUCCESS;
-
- if (lock->interproc->filedes != -1) {
- if (sem_close((sem_t *)lock->interproc->filedes) < 0) {
- stat = errno;
- }
- }
- return stat;
-}
-
-static apr_status_t posix_create(apr_lock_t *new, const char *fname)
-{
- sem_t *psem;
- apr_status_t stat;
- char semname[14];
- unsigned long epoch;
-
- new->interproc = apr_palloc(new->pool, sizeof(*new->interproc));
- /*
- * This bogusness is to follow what appears to be the
- * lowest common denominator in Posix semaphore naming:
- * - start with '/'
- * - be at most 14 chars
- * - be unique and not match anything on the filesystem
- *
- * Because of this, we ignore fname and craft our own.
- *
- * FIXME: There is a small window of opportunity where
- * instead of getting a new semaphore descriptor, we get
- * a previously obtained one. This can happen if the requests
- * are made at the "same time" (within a second, due to the
- * apr_time_now() call) and in the small span of time between
- * the sem_open and the sem_unlink. Use of O_EXCL does not
- * help here however...
- */
- epoch = apr_time_now() / APR_USEC_PER_SEC;
- apr_snprintf(semname, sizeof(semname), "/ApR.%lx", epoch);
- psem = sem_open((const char *) semname, O_CREAT, 0644, 1);
-
- if (psem == (sem_t *)SEM_FAILED) {
- stat = errno;
- posix_cleanup(new);
- return stat;
- }
- /* Ahhh. The joys of Posix sems. Predelete it... */
- sem_unlink((const char *) semname);
- new->interproc->filedes = (int)psem; /* Ugg */
- apr_pool_cleanup_register(new->pool, (void *)new, posix_cleanup,
- apr_pool_cleanup_null);
- return APR_SUCCESS;
-}
-
-static apr_status_t posix_acquire(apr_lock_t *lock)
-{
- int rc;
-
- if ((rc = sem_wait((sem_t *)lock->interproc->filedes)) < 0) {
- return errno;
- }
- lock->curr_locked = 1;
- return APR_SUCCESS;
-}
-
-static apr_status_t posix_release(apr_lock_t *lock)
-{
- int rc;
-
- if ((rc = sem_post((sem_t *)lock->interproc->filedes)) < 0) {
- return errno;
- }
- lock->curr_locked = 0;
- return APR_SUCCESS;
-}
-
-static apr_status_t posix_destroy(apr_lock_t *lock)
-{
- apr_status_t stat;
-
- if ((stat = posix_cleanup(lock)) == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->pool, lock, posix_cleanup);
- return APR_SUCCESS;
- }
- return stat;
-}
-
-static apr_status_t posix_child_init(apr_lock_t **lock, apr_pool_t *cont, const char *fname)
-{
- return APR_SUCCESS;
-}
-
-const apr_unix_lock_methods_t apr_unix_posix_methods =
-{
-#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS
- APR_PROCESS_LOCK_MECH_IS_GLOBAL,
-#else
- 0,
-#endif
- posix_create,
- posix_acquire,
- NULL, /* no tryacquire */
- NULL, /* no rw lock */
- NULL, /* no rw lock */
- posix_release,
- posix_destroy,
- posix_child_init
-};
-
-#endif /* Posix sem implementation */
-
-#if APR_HAS_SYSVSEM_SERIALIZE
-
-static struct sembuf op_on;
-static struct sembuf op_off;
-
-static void sysv_setup(void)
-{
- op_on.sem_num = 0;
- op_on.sem_op = -1;
- op_on.sem_flg = SEM_UNDO;
- op_off.sem_num = 0;
- op_off.sem_op = 1;
- op_off.sem_flg = SEM_UNDO;
-}
-
-static apr_status_t sysv_cleanup(void *lock_)
-{
- apr_lock_t *lock=lock_;
- union semun ick;
- apr_status_t stat = APR_SUCCESS;
-
- if (lock->interproc->filedes != -1) {
- ick.val = 0;
- if (semctl(lock->interproc->filedes, 0, IPC_RMID, ick) < 0) {
- stat = errno;
- }
- }
- return stat;
-}
-
-static apr_status_t sysv_create(apr_lock_t *new, const char *fname)
-{
- union semun ick;
- apr_status_t stat;
-
- new->interproc = apr_palloc(new->pool, sizeof(*new->interproc));
- new->interproc->filedes = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
-
- if (new->interproc->filedes < 0) {
- stat = errno;
- sysv_cleanup(new);
- return stat;
- }
- ick.val = 1;
- if (semctl(new->interproc->filedes, 0, SETVAL, ick) < 0) {
- stat = errno;
- sysv_cleanup(new);
- return stat;
- }
- new->curr_locked = 0;
- apr_pool_cleanup_register(new->pool, (void *)new, sysv_cleanup,
- apr_pool_cleanup_null);
- return APR_SUCCESS;
-}
-
-static apr_status_t sysv_acquire(apr_lock_t *lock)
-{
- int rc;
-
- do {
- rc = semop(lock->interproc->filedes, &op_on, 1);
- } while (rc < 0 && errno == EINTR);
- if (rc < 0) {
- return errno;
- }
- lock->curr_locked = 1;
- return APR_SUCCESS;
-}
-
-static apr_status_t sysv_release(apr_lock_t *lock)
-{
- int rc;
-
- do {
- rc = semop(lock->interproc->filedes, &op_off, 1);
- } while (rc < 0 && errno == EINTR);
- if (rc < 0) {
- return errno;
- }
- lock->curr_locked = 0;
- return APR_SUCCESS;
-}
-
-static apr_status_t sysv_destroy(apr_lock_t *lock)
-{
- apr_status_t stat;
-
- if ((stat = sysv_cleanup(lock)) == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->pool, lock, sysv_cleanup);
- return APR_SUCCESS;
- }
- return stat;
-}
-
-static apr_status_t sysv_child_init(apr_lock_t **lock, apr_pool_t *cont, const char *fname)
-{
- return APR_SUCCESS;
-}
-
-const apr_unix_lock_methods_t apr_unix_sysv_methods =
-{
-#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS
- APR_PROCESS_LOCK_MECH_IS_GLOBAL,
-#else
- 0,
-#endif
- sysv_create,
- sysv_acquire,
- NULL, /* no tryacquire */
- NULL, /* no rw lock */
- NULL, /* no rw lock */
- sysv_release,
- sysv_destroy,
- sysv_child_init
-};
-
-#endif /* SysV sem implementation */
-
-#if APR_HAS_PROC_PTHREAD_SERIALIZE
-
-static void proc_pthread_setup(void)
-{
-}
-
-static apr_status_t proc_pthread_cleanup(void *lock_)
-{
- apr_lock_t *lock=lock_;
- apr_status_t stat;
-
- if (lock->curr_locked == 1) {
- if ((stat = pthread_mutex_unlock(lock->pthread_interproc))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
- return stat;
- }
- if (munmap((caddr_t)lock->pthread_interproc, sizeof(pthread_mutex_t))){
- return errno;
- }
- }
- return APR_SUCCESS;
-}
-
-static apr_status_t proc_pthread_create(apr_lock_t *new, const char *fname)
-{
- apr_status_t stat;
- int fd;
- pthread_mutexattr_t mattr;
-
- fd = open("/dev/zero", O_RDWR);
- if (fd < 0) {
- return errno;
- }
-
- new->pthread_interproc = (pthread_mutex_t *)mmap((caddr_t) 0,
- sizeof(pthread_mutex_t),
- PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- if (new->pthread_interproc == (pthread_mutex_t *) (caddr_t) -1) {
- return errno;
- }
- close(fd);
- if ((stat = pthread_mutexattr_init(&mattr))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
- proc_pthread_cleanup(new);
- return stat;
- }
- if ((stat = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
- proc_pthread_cleanup(new);
- return stat;
- }
-
-#ifdef HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP
- if ((stat = pthread_mutexattr_setrobust_np(&mattr,
- PTHREAD_MUTEX_ROBUST_NP))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
- proc_pthread_cleanup(new);
- return stat;
- }
- if ((stat = pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
- proc_pthread_cleanup(new);
- return stat;
- }
-#endif
-
- if ((stat = pthread_mutex_init(new->pthread_interproc, &mattr))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
- proc_pthread_cleanup(new);
- return stat;
- }
-
- if ((stat = pthread_mutexattr_destroy(&mattr))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
- proc_pthread_cleanup(new);
- return stat;
- }
-
- new->curr_locked = 0;
- apr_pool_cleanup_register(new->pool, (void *)new, proc_pthread_cleanup,
- apr_pool_cleanup_null);
- return APR_SUCCESS;
-}
-
-static apr_status_t proc_pthread_acquire(apr_lock_t *lock)
-{
- apr_status_t stat;
-
- if ((stat = pthread_mutex_lock(lock->pthread_interproc))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
-#ifdef HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP
- /* Okay, our owner died. Let's try to make it consistent again. */
- if (stat == EOWNERDEAD) {
- pthread_mutex_consistent_np(lock->pthread_interproc);
- }
- else
- return stat;
-#else
- return stat;
-#endif
- }
- lock->curr_locked = 1;
- return APR_SUCCESS;
-}
-
-static apr_status_t proc_pthread_release(apr_lock_t *lock)
-{
- apr_status_t stat;
-
- if ((stat = pthread_mutex_unlock(lock->pthread_interproc))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
- return stat;
- }
- lock->curr_locked = 0;
- return APR_SUCCESS;
-}
-
-static apr_status_t proc_pthread_destroy(apr_lock_t *lock)
-{
- apr_status_t stat;
- if ((stat = proc_pthread_cleanup(lock)) == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->pool, lock, proc_pthread_cleanup);
- return APR_SUCCESS;
- }
- return stat;
-}
-
-static apr_status_t proc_pthread_child_init(apr_lock_t **lock,
- apr_pool_t *cont,
- const char *fname)
-{
- return APR_SUCCESS;
-}
-
-const apr_unix_lock_methods_t apr_unix_proc_pthread_methods =
-{
- APR_PROCESS_LOCK_MECH_IS_GLOBAL,
- proc_pthread_create,
- proc_pthread_acquire,
- NULL, /* no tryacquire */
- NULL, /* no rw lock */
- NULL, /* no rw lock */
- proc_pthread_release,
- proc_pthread_destroy,
- proc_pthread_child_init
-};
-
-#endif
-
-#if APR_HAS_FCNTL_SERIALIZE
-
-static struct flock lock_it;
-static struct flock unlock_it;
-
-static apr_status_t fcntl_release(apr_lock_t *);
-
-static void fcntl_setup(void)
-{
- lock_it.l_whence = SEEK_SET; /* from current point */
- lock_it.l_start = 0; /* -"- */
- lock_it.l_len = 0; /* until end of file */
- lock_it.l_type = F_WRLCK; /* set exclusive/write lock */
- lock_it.l_pid = 0; /* pid not actually interesting */
- unlock_it.l_whence = SEEK_SET; /* from current point */
- unlock_it.l_start = 0; /* -"- */
- unlock_it.l_len = 0; /* until end of file */
- unlock_it.l_type = F_UNLCK; /* set exclusive/write lock */
- unlock_it.l_pid = 0; /* pid not actually interesting */
-}
-
-static apr_status_t fcntl_cleanup(void *lock_)
-{
- apr_status_t status;
- apr_lock_t *lock=lock_;
-
- if (lock->curr_locked == 1) {
- status = fcntl_release(lock);
- if (status != APR_SUCCESS)
- return status;
- }
-
- return APR_SUCCESS;
-}
-
-static apr_status_t fcntl_create(apr_lock_t *new, const char *fname)
-{
- int rv;
-
- if (fname) {
- new->fname = apr_pstrdup(new->pool, fname);
- rv = apr_file_open(&new->interproc, new->fname,
- APR_CREATE | APR_WRITE | APR_EXCL, 0644, new->pool);
- }
- else {
- new->fname = apr_pstrdup(new->pool, "/tmp/aprXXXXXX");
- rv = apr_file_mktemp(&new->interproc, new->fname, 0, new->pool);
- }
-
- if (rv != APR_SUCCESS) {
- fcntl_cleanup(new);
- return rv;
- }
-
- new->curr_locked=0;
- unlink(new->fname);
- apr_pool_cleanup_register(new->pool, (void*)new, fcntl_cleanup,
- apr_pool_cleanup_null);
- return APR_SUCCESS;
-}
-
-static apr_status_t fcntl_acquire(apr_lock_t *lock)
-{
- int rc;
-
- do {
- rc = fcntl(lock->interproc->filedes, F_SETLKW, &lock_it);
- } while (rc < 0 && errno == EINTR);
- if (rc < 0) {
- return errno;
- }
- lock->curr_locked=1;
- return APR_SUCCESS;
-}
-
-static apr_status_t fcntl_release(apr_lock_t *lock)
-{
- int rc;
-
- do {
- rc = fcntl(lock->interproc->filedes, F_SETLKW, &unlock_it);
- } while (rc < 0 && errno == EINTR);
- if (rc < 0) {
- return errno;
- }
- lock->curr_locked=0;
- return APR_SUCCESS;
-}
-
-static apr_status_t fcntl_destroy(apr_lock_t *lock)
-{
- apr_status_t stat;
- if ((stat = fcntl_cleanup(lock)) == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->pool, lock, fcntl_cleanup);
- return APR_SUCCESS;
- }
- return stat;
-}
-
-static apr_status_t fcntl_child_init(apr_lock_t **lock, apr_pool_t *cont,
- const char *fname)
-{
- return APR_SUCCESS;
-}
-
-const apr_unix_lock_methods_t apr_unix_fcntl_methods =
-{
-#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS
- APR_PROCESS_LOCK_MECH_IS_GLOBAL,
-#else
- 0,
-#endif
- fcntl_create,
- fcntl_acquire,
- NULL, /* no tryacquire */
- NULL, /* no rw lock */
- NULL, /* no rw lock */
- fcntl_release,
- fcntl_destroy,
- fcntl_child_init
-};
-
-#endif /* fcntl implementation */
-
-#if APR_HAS_FLOCK_SERIALIZE
-
-static apr_status_t flock_release(apr_lock_t *);
-
-static void flock_setup(void)
-{
-}
-
-static apr_status_t flock_cleanup(void *lock_)
-{
- apr_status_t status;
- apr_lock_t *lock=lock_;
-
- if (lock->curr_locked == 1) {
- status = flock_release(lock);
- if (status != APR_SUCCESS)
- return status;
- }
- apr_file_close(lock->interproc);
- unlink(lock->fname);
- return APR_SUCCESS;
-}
-
-static apr_status_t flock_create(apr_lock_t *new, const char *fname)
-{
- int rv;
-
- if (fname) {
- new->fname = apr_pstrdup(new->pool, fname);
- rv = apr_file_open(&new->interproc, new->fname,
- APR_CREATE | APR_WRITE | APR_EXCL, 0644, new->pool);
- }
- else {
- new->fname = apr_pstrdup(new->pool, "/tmp/aprXXXXXX");
- rv = apr_file_mktemp(&new->interproc, new->fname, 0, new->pool);
- }
-
- if (rv != APR_SUCCESS) {
- apr_status_t stat = errno;
-
- flock_cleanup(new);
- return stat;
- }
- new->curr_locked = 0;
- apr_pool_cleanup_register(new->pool, (void *)new, flock_cleanup,
- apr_pool_cleanup_null);
- return APR_SUCCESS;
-}
-
-static apr_status_t flock_acquire(apr_lock_t *lock)
-{
- int rc;
-
- do {
- rc = flock(lock->interproc->filedes, LOCK_EX);
- } while (rc < 0 && errno == EINTR);
- if (rc < 0) {
- return errno;
- }
- lock->curr_locked = 1;
- return APR_SUCCESS;
-}
-
-static apr_status_t flock_release(apr_lock_t *lock)
-{
- int rc;
-
- do {
- rc = flock(lock->interproc->filedes, LOCK_UN);
- } while (rc < 0 && errno == EINTR);
- if (rc < 0) {
- return errno;
- }
- lock->curr_locked = 0;
- return APR_SUCCESS;
-}
-
-static apr_status_t flock_destroy(apr_lock_t *lock)
-{
- apr_status_t stat;
- if ((stat = flock_cleanup(lock)) == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->pool, lock, flock_cleanup);
- return APR_SUCCESS;
- }
- return stat;
-}
-
-static apr_status_t flock_child_init(apr_lock_t **lock, apr_pool_t *cont,
- const char *fname)
-{
- apr_lock_t *new;
- int rv;
-
- new = (apr_lock_t *)apr_palloc(cont, sizeof(apr_lock_t));
-
- memcpy(new, *lock, sizeof *new);
- new->pool = cont;
- new->fname = apr_pstrdup(cont, fname);
- rv = apr_file_open(&new->interproc, new->fname,
- APR_CREATE | APR_WRITE, 0600, new->pool);
- if (rv != APR_SUCCESS) {
- apr_status_t stat = errno;
-
- flock_destroy(new);
- return stat;
- }
- *lock = new;
- return APR_SUCCESS;
-}
-
-const apr_unix_lock_methods_t apr_unix_flock_methods =
-{
-#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS
- APR_PROCESS_LOCK_MECH_IS_GLOBAL,
-#else
- 0,
-#endif
- flock_create,
- flock_acquire,
- NULL, /* no tryacquire */
- NULL, /* no rw lock */
- NULL, /* no rw lock */
- flock_release,
- flock_destroy,
- flock_child_init
-};
-
-#endif /* flock implementation */
-
-void apr_unix_setup_lock(void)
-{
-#if APR_HAS_POSIXSEM_SERIALIZE
- posix_setup();
-#endif
-#if APR_HAS_SYSVSEM_SERIALIZE
- sysv_setup();
-#endif
-#if APR_HAS_PROC_PTHREAD_SERIALIZE
- proc_pthread_setup();
-#endif
-#if APR_HAS_FCNTL_SERIALIZE
- fcntl_setup();
-#endif
-#if APR_HAS_FLOCK_SERIALIZE
- flock_setup();
-#endif
-}
diff --git a/locks/unix/intraproc.c b/locks/unix/intraproc.c
deleted file mode 100644
index a559e4562..000000000
--- a/locks/unix/intraproc.c
+++ /dev/null
@@ -1,229 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-#include "locks.h"
-
-#if APR_HAS_THREADS
-
-#if (APR_USE_PTHREAD_SERIALIZE)
-
-static apr_status_t lock_intra_cleanup(void *data)
-{
- apr_lock_t *lock = (apr_lock_t *) data;
- apr_status_t stat;
-
- pthread_mutex_unlock(lock->intraproc);
- stat = pthread_mutex_destroy(lock->intraproc);
-#ifdef PTHREAD_SETS_ERRNO
- if (stat) {
- stat = errno;
- }
-#endif
- return stat;
-}
-
-static apr_status_t intra_create(apr_lock_t *new, const char *fname)
-{
- apr_status_t stat;
- pthread_mutexattr_t mattr;
-
- new->intraproc = (pthread_mutex_t *)apr_palloc(new->pool,
- sizeof(pthread_mutex_t));
- if (new->intraproc == NULL) {
- return errno;
- }
- if ((stat = pthread_mutexattr_init(&mattr))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
- lock_intra_cleanup(new);
- return stat;
- }
-
- if ((stat = pthread_mutex_init(new->intraproc, &mattr))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
- lock_intra_cleanup(new);
- return stat;
- }
-
- if ((stat = pthread_mutexattr_destroy(&mattr))) {
-#ifdef PTHREAD_SETS_ERRNO
- stat = errno;
-#endif
- lock_intra_cleanup(new);
- return stat;
- }
-
- new->curr_locked = 0;
- apr_pool_cleanup_register(new->pool, (void *)new, lock_intra_cleanup,
- apr_pool_cleanup_null);
- return APR_SUCCESS;
-}
-
-static apr_status_t intra_acquire(apr_lock_t *lock)
-{
- apr_status_t stat;
-
- stat = pthread_mutex_lock(lock->intraproc);
-#ifdef PTHREAD_SETS_ERRNO
- if (stat) {
- stat = errno;
- }
-#endif
- return stat;
-}
-
-static apr_status_t intra_tryacquire(apr_lock_t *lock)
-{
- apr_status_t stat;
-
- stat = pthread_mutex_trylock(lock->intraproc);
-#ifdef PTHREAD_SETS_ERRNO
- if (stat) {
- stat = errno;
- }
-#endif
- /* Normalize the return code. */
- if (stat == EBUSY)
- stat = APR_EBUSY;
- return stat;
-}
-
-static apr_status_t intra_release(apr_lock_t *lock)
-{
- apr_status_t status;
-
- status = pthread_mutex_unlock(lock->intraproc);
-#ifdef PTHREAD_SETS_ERRNO
- if (status) {
- status = errno;
- }
-#endif
- return status;
-}
-
-static apr_status_t intra_destroy(apr_lock_t *lock)
-{
- apr_status_t stat;
- if ((stat = lock_intra_cleanup(lock)) == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->pool, lock, lock_intra_cleanup);
- return APR_SUCCESS;
- }
- return stat;
-}
-
-#endif /* APR_USE_PTHREAD_SERIALIZE */
-
-const apr_unix_lock_methods_t apr_unix_intra_methods =
-{
- 0,
- intra_create,
- intra_acquire,
- intra_tryacquire,
- NULL, /* no read lock concept */
- NULL, /* no write lock concept */
- intra_release,
- intra_destroy,
- NULL /* no child init */
-};
-
-#if APR_HAS_RWLOCK_SERIALIZE
-static apr_status_t rwlock_create(apr_lock_t *new, const char *fname)
-{
- /* XXX check retcode */
- pthread_rwlock_init(&new->rwlock, NULL);
- return APR_SUCCESS;
-}
-
-static apr_status_t rwlock_acquire_read(apr_lock_t *lock)
-{
- /* XXX PTHREAD_SETS_ERRNO crap? */
- return pthread_rwlock_rdlock(&lock->rwlock);
-}
-
-static apr_status_t rwlock_acquire_write(apr_lock_t *lock)
-{
- /* XXX PTHREAD_SETS_ERRNO crap? */
- return pthread_rwlock_wrlock(&lock->rwlock);
-}
-
-static apr_status_t rwlock_release(apr_lock_t *lock)
-{
- /* XXX PTHREAD_SETS_ERRNO crap? */
- return pthread_rwlock_unlock(&lock->rwlock);
-}
-
-static apr_status_t rwlock_destroy(apr_lock_t *lock)
-{
- /* XXX PTHREAD_SETS_ERRNO crap? */
- return pthread_rwlock_destroy(&lock->rwlock);
-}
-
-const apr_unix_lock_methods_t apr_unix_rwlock_methods =
-{
- 0,
- rwlock_create,
- NULL, /* no standard acquire method; app better not call :) */
- NULL, /* no standard tryacquire method; app better not call :) */
- rwlock_acquire_read,
- rwlock_acquire_write,
- rwlock_release,
- rwlock_destroy,
- NULL /* no child init method */
-};
-#endif
-
-#endif /* APR_HAS_THREADS */
diff --git a/locks/unix/locks.c b/locks/unix/locks.c
deleted file mode 100644
index b6b3a1ba4..000000000
--- a/locks/unix/locks.c
+++ /dev/null
@@ -1,412 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-#include "locks.h"
-#include "apr_strings.h"
-#include "apr_portable.h"
-
-static apr_status_t lockall_create(apr_lock_t *new, const char *fname)
-{
- apr_status_t rv;
-
- if ((rv = new->inter_meth->create(new, fname)) != APR_SUCCESS) {
- return rv;
- }
- if ((rv = new->intra_meth->create(new, fname)) != APR_SUCCESS) {
- return rv;
- }
- return APR_SUCCESS;
-}
-
-static apr_status_t lockall_acquire(apr_lock_t *lock)
-{
- apr_status_t rv;
-
- if ((rv = lock->intra_meth->acquire(lock)) != APR_SUCCESS) {
- return rv;
- }
- if ((rv = lock->inter_meth->acquire(lock)) != APR_SUCCESS) {
- return rv;
- }
- return APR_SUCCESS;
-}
-
-static apr_status_t lockall_release(apr_lock_t *lock)
-{
- apr_status_t rv;
-
- if ((rv = lock->intra_meth->release(lock)) != APR_SUCCESS) {
- return rv;
- }
- if ((rv = lock->inter_meth->release(lock)) != APR_SUCCESS) {
- return rv;
- }
- return APR_SUCCESS;
-}
-
-static apr_status_t lockall_destroy(apr_lock_t *lock)
-{
- apr_status_t rv;
-
- if ((rv = lock->intra_meth->destroy(lock)) != APR_SUCCESS) {
- return rv;
- }
- if ((rv = lock->inter_meth->destroy(lock)) != APR_SUCCESS) {
- return rv;
- }
- return APR_SUCCESS;
-}
-
-static apr_status_t lockall_child_init(apr_lock_t **lock, apr_pool_t *pool,
- const char *fname)
-{
- /* no child init for intra lock */
- return (*lock)->inter_meth->child_init(lock, pool, fname);
-}
-
-static const struct apr_unix_lock_methods_t lockall_methods =
-{
- 0,
- lockall_create,
- lockall_acquire,
- NULL, /* no tryacquire concept */
- NULL, /* no read lock concept */
- NULL, /* no write lock concept */
- lockall_release,
- lockall_destroy,
- lockall_child_init
-};
-
-static apr_status_t choose_method(apr_lock_t *new, apr_lockmech_e mech)
-{
- switch (mech) {
- case APR_LOCK_FCNTL:
-#if APR_HAS_FCNTL_SERIALIZE
- new->inter_meth = &apr_unix_fcntl_methods;
-#else
- return APR_ENOTIMPL;
-#endif
- break;
- case APR_LOCK_FLOCK:
-#if APR_HAS_FLOCK_SERIALIZE
- new->inter_meth = &apr_unix_flock_methods;
-#else
- return APR_ENOTIMPL;
-#endif
- break;
- case APR_LOCK_SYSVSEM:
-#if APR_HAS_SYSVSEM_SERIALIZE
- new->inter_meth = &apr_unix_sysv_methods;
-#else
- return APR_ENOTIMPL;
-#endif
- break;
- case APR_LOCK_POSIXSEM:
-#if APR_HAS_POSIXSEM_SERIALIZE
- new->inter_meth = &apr_unix_posix_methods;
-#else
- return APR_ENOTIMPL;
-#endif
- break;
- case APR_LOCK_PROC_PTHREAD:
-#if APR_HAS_PROC_PTHREAD_SERIALIZE
- new->inter_meth = &apr_unix_proc_pthread_methods;
-#else
- return APR_ENOTIMPL;
-#endif
- break;
- case APR_LOCK_DEFAULT:
-#if APR_USE_FLOCK_SERIALIZE
- new->inter_meth = &apr_unix_flock_methods;
-#elif APR_USE_POSIXSEM_SERIALIZE
- new->inter_meth = &apr_unix_posix_methods;
-#elif APR_USE_SYSVSEM_SERIALIZE
- new->inter_meth = &apr_unix_sysv_methods;
-#elif APR_USE_FCNTL_SERIALIZE
- new->inter_meth = &apr_unix_fcntl_methods;
-#elif APR_USE_PROC_PTHREAD_SERIALIZE
- new->inter_meth = &apr_unix_proc_pthread_methods;
-#else
- return APR_ENOTIMPL;
-#endif
- break;
- default:
- return APR_ENOTIMPL;
- }
- return APR_SUCCESS;
-}
-
-static apr_status_t create_lock(apr_lock_t *new, apr_lockmech_e mech, const char *fname)
-{
- apr_status_t stat;
-
- if (new->scope != APR_INTRAPROCESS) {
- if ((stat = choose_method(new, mech)) != APR_SUCCESS) {
- return stat;
- }
- }
-
- if (new->scope != APR_CROSS_PROCESS) {
-#if APR_HAS_THREADS
- if (new->type == APR_READWRITE) {
-#if APR_HAS_RWLOCK_SERIALIZE
- new->intra_meth = &apr_unix_rwlock_methods;
-#else
- return APR_ENOTIMPL; /* 'cause we don't have rwlocks */
-#endif
- }
- else {
- new->intra_meth = &apr_unix_intra_methods;
- }
-#else
- if (new->scope == APR_INTRAPROCESS) {
- return APR_ENOTIMPL; /* 'cause we don't have threads */
- }
-#endif
- }
-
- switch (new->scope) {
- case APR_LOCKALL:
- if (new->inter_meth->flags & APR_PROCESS_LOCK_MECH_IS_GLOBAL) {
- new->meth = new->inter_meth;
- }
- else {
- new->meth = &lockall_methods;
- }
- break;
- case APR_CROSS_PROCESS:
- new->meth = new->inter_meth;
- break;
- case APR_INTRAPROCESS:
- new->meth = new->intra_meth;
- }
-
- if ((stat = new->meth->create(new, fname)) != APR_SUCCESS) {
- return stat;
- }
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_create(apr_lock_t **lock, apr_locktype_e type,
- apr_lockscope_e scope, apr_lockmech_e mech,
- const char *fname, apr_pool_t *pool)
-{
- apr_lock_t *new;
- apr_status_t stat;
-
- new = (apr_lock_t *)apr_pcalloc(pool, sizeof(apr_lock_t));
-
- new->pool = pool;
- new->type = type;
- new->scope = scope;
-#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE || APR_HAS_POSIXSEM_SERIALIZE
- new->interproc = NULL;
-#endif
-
- if ((stat = create_lock(new, mech, fname)) != APR_SUCCESS)
- return stat;
-
- *lock = new;
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_acquire(apr_lock_t *lock)
-{
- apr_status_t stat;
-
-#if APR_HAS_THREADS
- if (apr_os_thread_equal(lock->owner, apr_os_thread_current())) {
- lock->owner_ref++;
- return APR_SUCCESS;
- }
-#endif
-
- if ((stat = lock->meth->acquire(lock)) != APR_SUCCESS) {
- return stat;
- }
-
-#if APR_HAS_THREADS
- lock->owner = apr_os_thread_current();
- lock->owner_ref = 1;
-#endif
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_tryacquire(apr_lock_t *lock)
-{
- apr_status_t stat;
-
-#if APR_HAS_THREADS
- if (apr_os_thread_equal(lock->owner, apr_os_thread_current())) {
- lock->owner_ref++;
- return APR_SUCCESS;
- }
-#endif
-
- if ((stat = lock->meth->tryacquire(lock)) != APR_SUCCESS) {
- return stat;
- }
-
-#if APR_HAS_THREADS
- lock->owner = apr_os_thread_current();
- lock->owner_ref = 1;
-#endif
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_acquire_rw(apr_lock_t *lock,
- apr_readerwriter_e e)
-{
- switch (e)
- {
- case APR_READER:
- return lock->meth->acquire_read(lock);
- case APR_WRITER:
- return lock->meth->acquire_write(lock);
- }
- return APR_ENOTIMPL;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_release(apr_lock_t *lock)
-{
- apr_status_t stat;
-
-#if APR_HAS_THREADS
- if (apr_os_thread_equal(lock->owner, apr_os_thread_current())) {
- lock->owner_ref--;
- if (lock->owner_ref > 0)
- return APR_SUCCESS;
- }
-#endif
-
- if ((stat = lock->meth->release(lock)) != APR_SUCCESS) {
- return stat;
- }
-
-#if APR_HAS_THREADS
- memset(&lock->owner, 0, sizeof lock->owner);
- lock->owner_ref = 0;
-#endif
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_destroy(apr_lock_t *lock)
-{
- return lock->meth->destroy(lock);
-}
-
-APR_DECLARE(apr_status_t) apr_lock_child_init(apr_lock_t **lock, const char *fname,
- apr_pool_t *cont)
-{
- if ((*lock)->scope != APR_INTRAPROCESS)
- return (*lock)->meth->child_init(lock, cont, fname);
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_data_get(apr_lock_t *lock, const char *key, void *data)
-{
- return apr_pool_userdata_get(data, key, lock->pool);
-}
-
-APR_DECLARE(apr_status_t) apr_lock_data_set(apr_lock_t *lock, void *data, const char *key,
- apr_status_t (*cleanup) (void *))
-{
- return apr_pool_userdata_set(data, key, cleanup, lock->pool);
-}
-
-APR_DECLARE(apr_status_t) apr_os_lock_get(apr_os_lock_t *oslock, apr_lock_t *lock)
-{
-#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE || APR_HAS_POSIXSEM_SERIALIZE
- oslock->crossproc = lock->interproc->filedes;
-#endif
-#if APR_HAS_PROC_PTHREAD_SERIALIZE
- oslock->pthread_interproc = lock->pthread_interproc;
-#endif
-#if APR_HAS_THREADS
-#if APR_USE_PTHREAD_SERIALIZE
- oslock->intraproc = lock->intraproc;
-#endif
-#endif
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_os_lock_put(apr_lock_t **lock, apr_os_lock_t *thelock,
- apr_pool_t *pool)
-{
- if (pool == NULL) {
- return APR_ENOPOOL;
- }
- if ((*lock) == NULL) {
- (*lock) = (apr_lock_t *)apr_pcalloc(pool, sizeof(apr_lock_t));
- (*lock)->pool = pool;
- }
-#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE || APR_HAS_POSIXSEM_SERIALIZE
- apr_os_file_put(&(*lock)->interproc, &thelock->crossproc, 0, pool);
-#endif
-#if APR_HAS_PROC_PTHREAD_SERIALIZE
- (*lock)->pthread_interproc = thelock->pthread_interproc;
-#endif
-#if APR_HAS_THREADS
-#if (APR_USE_PTHREAD_SERIALIZE)
- (*lock)->intraproc = thelock->intraproc;
-#endif
-#endif
- return APR_SUCCESS;
-}
-
diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c
index e1a548598..5808e7e39 100644
--- a/locks/unix/proc_mutex.c
+++ b/locks/unix/proc_mutex.c
@@ -817,10 +817,8 @@ static apr_status_t proc_mutex_create(apr_proc_mutex_t *new_mutex, apr_lockmech_
{
apr_status_t rv;
- if (new_mutex->scope != APR_INTRAPROCESS) {
- if ((rv = proc_mutex_choose_method(new_mutex, mech)) != APR_SUCCESS) {
- return rv;
- }
+ if ((rv = proc_mutex_choose_method(new_mutex, mech)) != APR_SUCCESS) {
+ return rv;
}
new_mutex->meth = new_mutex->inter_meth;
diff --git a/locks/win32/locks.c b/locks/win32/locks.c
deleted file mode 100644
index c23906f05..000000000
--- a/locks/win32/locks.c
+++ /dev/null
@@ -1,303 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-#include "apr.h"
-#include "apr_private.h"
-#include "apr_general.h"
-#include "apr_strings.h"
-#include "win32/locks.h"
-#include "apr_portable.h"
-#include "misc.h"
-
-static apr_status_t lock_cleanup(void *lock_)
-{
- apr_lock_t *lock = lock_;
-
- switch (lock->type)
- {
- case APR_MUTEX:
- if (lock->scope == APR_INTRAPROCESS) {
- DeleteCriticalSection(&lock->section);
- return APR_SUCCESS;
- } else {
- if (CloseHandle(lock->mutex) == 0) {
- return apr_get_os_error();
- }
- }
- break;
- case APR_READWRITE:
- return APR_ENOTIMPL;
- }
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_create(apr_lock_t **lock,
- apr_locktype_e type,
- apr_lockscope_e scope,
- apr_lockmech_e mech,
- const char *fname,
- apr_pool_t *pool)
-{
- apr_lock_t *newlock;
- SECURITY_ATTRIBUTES sec;
-
- /* FIXME: Remove when read write locks implemented. */
- if (type == APR_READWRITE)
- return APR_ENOTIMPL;
-
- if (mech != APR_LOCK_DEFAULT) {
- return APR_ENOTIMPL;
- }
-
- newlock = (apr_lock_t *)apr_palloc(pool, sizeof(apr_lock_t));
-
- newlock->pool = pool;
- /* ToDo: How to handle the case when no pool is available?
- * How to cleanup the storage properly?
- */
- newlock->type = type;
- newlock->scope = scope;
- sec.nLength = sizeof(SECURITY_ATTRIBUTES);
- sec.lpSecurityDescriptor = NULL;
-
- if (scope == APR_CROSS_PROCESS || scope == APR_LOCKALL) {
- sec.bInheritHandle = TRUE;
- }
- else {
- sec.bInheritHandle = FALSE;
- }
-
- if (scope == APR_INTRAPROCESS) {
- if (fname) {
- newlock->fname = apr_pstrdup(pool, fname);
- }
- else {
- newlock->fname = NULL;
- }
- InitializeCriticalSection(&newlock->section);
- } else {
- /* With Win2000 Terminal Services, the Mutex name can have a
- * "Global\" or "Local\" prefix to explicitly create the object
- * in the global or session name space. Without Terminal Service
- * running on Win2000, Global\ and Local\ are ignored. These
- * prefixes are only valid on Win2000+
- */
- if (fname) {
- if (apr_os_level >= APR_WIN_2000) {
- newlock->fname = apr_pstrcat(pool, "Global\\", fname, NULL);
- }
- else {
- newlock->fname = apr_pstrdup(pool, fname);
- }
- }
- else {
- newlock->fname = NULL;
- }
-
- newlock->mutex = CreateMutex(&sec, FALSE, newlock->fname);
- if (!newlock->mutex) {
- return apr_get_os_error();
- }
- }
- *lock = newlock;
- apr_pool_cleanup_register(newlock->pool, newlock, lock_cleanup,
- apr_pool_cleanup_null);
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_child_init(apr_lock_t **lock,
- const char *fname,
- apr_pool_t *pool)
-{
- /* This routine should not be called (and OpenMutex will fail if called)
- * on a INTRAPROCESS lock
- */
- (*lock) = (apr_lock_t *)apr_palloc(pool, sizeof(apr_lock_t));
-
- if (fname) {
- if (apr_os_level >= APR_WIN_2000) {
- (*lock)->fname = apr_pstrcat(pool, "Global\\", fname, NULL);
- }
- else {
- (*lock)->fname = apr_pstrdup(pool, fname);
- }
- }
- else {
- return APR_EINVAL;
- }
-
- (*lock)->mutex = OpenMutex(MUTEX_ALL_ACCESS, TRUE, fname);
-
- if ((*lock)->mutex == NULL) {
- return apr_get_os_error();
- }
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_acquire(apr_lock_t *lock)
-{
- DWORD rv;
- switch (lock->type)
- {
- case APR_MUTEX:
- if (lock->scope == APR_INTRAPROCESS) {
- EnterCriticalSection(&lock->section);
- return APR_SUCCESS;
- } else {
- rv = WaitForSingleObject(lock->mutex, INFINITE);
-
- if (rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) {
- return APR_SUCCESS;
- }
- }
- break;
- case APR_READWRITE:
- return APR_ENOTIMPL;
- }
-
- return apr_get_os_error();
-}
-
-APR_DECLARE(apr_status_t) apr_lock_tryacquire(apr_lock_t *lock)
-{
- return APR_ENOTIMPL;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_acquire_rw(apr_lock_t *lock,
- apr_readerwriter_e e)
-{
- switch (lock->type)
- {
- case APR_MUTEX:
- return APR_ENOTIMPL;
- case APR_READWRITE:
- switch (e)
- {
- case APR_READER:
- break;
- case APR_WRITER:
- break;
- }
- return APR_ENOTIMPL;
- }
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_release(apr_lock_t *lock)
-{
- switch (lock->type)
- {
- case APR_MUTEX:
- if (lock->scope == APR_INTRAPROCESS) {
- LeaveCriticalSection(&lock->section);
- return APR_SUCCESS;
- } else {
- if (ReleaseMutex(lock->mutex) == 0) {
- return apr_get_os_error();
- }
- }
- break;
- case APR_READWRITE:
- return APR_ENOTIMPL;
- }
-
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_destroy(apr_lock_t *lock)
-{
- apr_status_t stat;
-
- stat = lock_cleanup(lock);
- if (stat == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->pool, lock, lock_cleanup);
- }
- return stat;
-}
-
-APR_DECLARE(apr_status_t) apr_lock_data_get(apr_lock_t *lock, const char *key,
- void *data)
-{
- return apr_pool_userdata_get(data, key, lock->pool);
-}
-
-APR_DECLARE(apr_status_t) apr_lock_data_set(apr_lock_t *lock, void *data,
- const char *key,
- apr_status_t (*cleanup) (void *))
-{
- return apr_pool_userdata_set(data, key, cleanup, lock->pool);
-}
-
-APR_DECLARE(apr_status_t) apr_os_lock_get(apr_os_lock_t *thelock,
- apr_lock_t *lock)
-{
- *thelock = lock->mutex;
- return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_os_lock_put(apr_lock_t **lock,
- apr_os_lock_t *thelock,
- apr_pool_t *pool)
-{
- if (pool == NULL) {
- return APR_ENOPOOL;
- }
- if ((*lock) == NULL) {
- (*lock) = (apr_lock_t *)apr_palloc(pool, sizeof(apr_lock_t));
- (*lock)->pool = pool;
- }
- (*lock)->mutex = *thelock;
- return APR_SUCCESS;
-}