diff options
author | dreid <dreid@13f79535-47bb-0310-9956-ffa450edef68> | 2001-06-11 11:33:36 +0000 |
---|---|---|
committer | dreid <dreid@13f79535-47bb-0310-9956-ffa450edef68> | 2001-06-11 11:33:36 +0000 |
commit | f417994819dd38ecab933d48f31c9bf58369bc54 (patch) | |
tree | 3120600e1db8c7a716ab36ae7b3843e4e0ee95a2 /locks/beos | |
parent | c19b03a48d3d1ccab6a434db03a540d4f3c38242 (diff) | |
download | libapr-f417994819dd38ecab933d48f31c9bf58369bc54.tar.gz |
This has been on my ToDO list for a while, but essentially I've never
quite got around to changing the locks and so they were still identical
implementations, despite having different purposes :( So, until I get
the time to add the different impl. I'm simplifying what we had to make
them quicker and easier to maintain.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61754 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks/beos')
-rw-r--r-- | locks/beos/Makefile.in | 5 | ||||
-rw-r--r-- | locks/beos/crossproc.c | 129 | ||||
-rw-r--r-- | locks/beos/intraproc.c | 119 | ||||
-rw-r--r-- | locks/beos/locks.c | 142 |
4 files changed, 87 insertions, 308 deletions
diff --git a/locks/beos/Makefile.in b/locks/beos/Makefile.in index 8d5687f9d..d8d200cea 100644 --- a/locks/beos/Makefile.in +++ b/locks/beos/Makefile.in @@ -1,8 +1,5 @@ -TARGETS = \ - locks.lo \ - crossproc.lo \ - intraproc.lo +TARGETS = locks.lo # bring in rules.mk for standard functionality @INCLUDE_RULES@ diff --git a/locks/beos/crossproc.c b/locks/beos/crossproc.c deleted file mode 100644 index 317a76e35..000000000 --- a/locks/beos/crossproc.c +++ /dev/null @@ -1,129 +0,0 @@ -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2000-2001 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 "unix/apr_private.h" -#include "beos/locks.h" - -static apr_status_t lock_inter_cleanup(void * data) -{ - apr_lock_t *lock = (apr_lock_t*)data; - if (lock->ben_interproc != 0) { - /* we're still locked... */ - while (atomic_add(&lock->ben_interproc , -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->sem_interproc); - } - } - delete_sem(lock->sem_interproc); - return APR_SUCCESS; -} - -apr_status_t create_inter_lock(apr_lock_t *new) -{ - int32 stat; - - if ((stat = create_sem(0, "apr_interproc")) < B_NO_ERROR) { - lock_inter_cleanup(new); - return stat; - } - new->ben_interproc = 0; - new->sem_interproc = stat; - apr_pool_cleanup_register(new->pool, (void *)new, lock_inter_cleanup, - apr_pool_cleanup_null); - return APR_SUCCESS; -} - -apr_status_t lock_inter(apr_lock_t *lock) -{ - int32 stat; - - if (atomic_add(&lock->ben_interproc, 1) > 0){ - if ((stat = acquire_sem(lock->sem_interproc)) < B_NO_ERROR){ - atomic_add(&lock->ben_interproc, -1); - return stat; - } - } - return APR_SUCCESS; -} - -apr_status_t unlock_inter(apr_lock_t *lock) -{ - int32 stat; - - if (atomic_add(&lock->ben_interproc, -1) > 1){ - if ((stat = release_sem(lock->sem_interproc)) < B_NO_ERROR) { - atomic_add(&lock->ben_interproc, 1); - return stat; - } - } - return APR_SUCCESS; -} - -apr_status_t destroy_inter_lock(apr_lock_t *lock) -{ - apr_status_t stat; - if ((stat = lock_inter_cleanup(lock)) == APR_SUCCESS) { - apr_pool_cleanup_kill(lock->pool, lock, lock_inter_cleanup); - return APR_SUCCESS; - } - return stat; -} - -apr_status_t child_init_lock(apr_lock_t **lock, apr_pool_t *pool, const char *fname) -{ - return APR_SUCCESS; -} diff --git a/locks/beos/intraproc.c b/locks/beos/intraproc.c deleted file mode 100644 index c1847a390..000000000 --- a/locks/beos/intraproc.c +++ /dev/null @@ -1,119 +0,0 @@ -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2000-2001 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 "unix/apr_private.h" -#include "beos/locks.h" - -static apr_status_t lock_intra_cleanup(void *data) -{ - apr_lock_t *lock = (apr_lock_t *)data; - if (lock->ben_intraproc != 0) { - while (atomic_add(&lock->ben_intraproc , -1) > 1){ - release_sem (lock->sem_intraproc); - } - } - delete_sem(lock->sem_intraproc); - return APR_SUCCESS; -} - -apr_status_t create_intra_lock(apr_lock_t *new) -{ - int32 stat; - - if ((stat = create_sem(0, "apr_intraproc")) < B_NO_ERROR){ - lock_intra_cleanup(new); - return stat; - } - new->ben_intraproc = 0; - new->sem_intraproc = stat; - apr_pool_cleanup_register(new->pool, (void *)new, lock_intra_cleanup, - apr_pool_cleanup_null); - return APR_SUCCESS; -} - -apr_status_t lock_intra(apr_lock_t *lock) -{ - int32 stat; - - if (atomic_add (&lock->ben_intraproc, 1) > 0){ - if ((stat = acquire_sem(lock->sem_intraproc)) < B_NO_ERROR){ - atomic_add(&lock->ben_intraproc,-1); - return stat; - } - } - return APR_SUCCESS; -} - -apr_status_t unlock_intra(apr_lock_t *lock) -{ - int32 stat; - - if (atomic_add(&lock->ben_intraproc, -1) > 1){ - if ((stat = release_sem(lock->sem_intraproc)) < B_NO_ERROR) { - atomic_add(&lock->ben_intraproc, 1); - return stat; - } - } - return APR_SUCCESS; -} - -apr_status_t destroy_intra_lock(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; -} diff --git a/locks/beos/locks.c b/locks/beos/locks.c index ae854fc40..3603e5b56 100644 --- a/locks/beos/locks.c +++ b/locks/beos/locks.c @@ -56,6 +56,76 @@ #include "apr_strings.h" #include "apr_portable.h" + +/* At present we only have one implementation, so here it is :) */ +static apr_status_t _lock_cleanup(void * data) +{ + apr_lock_t *lock = (apr_lock_t*)data; + if (lock->ben != 0) { + /* we're still locked... */ + while (atomic_add(&lock->ben , -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->sem); + } + } + delete_sem(lock->sem); + 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->ben = 0; + new->sem = stat; + apr_pool_cleanup_register(new->pool, (void *)new, _lock_cleanup, + apr_pool_cleanup_null); + return APR_SUCCESS; +} + +static apr_status_t _lock(apr_lock_t *lock) +{ + int32 stat; + + if (atomic_add(&lock->ben, 1) > 0) { + if ((stat = acquire_sem(lock->sem)) < B_NO_ERROR) { + atomic_add(&lock->ben, -1); + return stat; + } + } + return APR_SUCCESS; +} + +static apr_status_t _unlock(apr_lock_t *lock) +{ + int32 stat; + + if (atomic_add(&lock->ben, -1) > 1) { + if ((stat = release_sem(lock->sem)) < B_NO_ERROR) { + atomic_add(&lock->ben, 1); + return stat; + } + } + return APR_SUCCESS; +} + +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_status_t apr_lock_create(apr_lock_t **lock, apr_locktype_e type, apr_lockscope_e scope, const char *fname, apr_pool_t *pool) @@ -76,16 +146,9 @@ apr_status_t apr_lock_create(apr_lock_t **lock, apr_locktype_e type, new->type = type; new->scope = scope; - if (scope != APR_CROSS_PROCESS) { - if ((stat = create_intra_lock(new)) != APR_SUCCESS) { - return stat; - } - } - if (scope != APR_INTRAPROCESS) { - if ((stat = create_inter_lock(new)) != APR_SUCCESS) { - return stat; - } - } + if ((stat = _create_lock(new)) != APR_SUCCESS) + return stat; + (*lock) = new; return APR_SUCCESS; } @@ -102,17 +165,10 @@ apr_status_t apr_lock_acquire(apr_lock_t *lock) switch (lock->type) { case APR_MUTEX: - if (lock->scope != APR_CROSS_PROCESS) { - if ((stat = lock_intra(lock)) != APR_SUCCESS) { - return stat; - } - } - if (lock->scope != APR_INTRAPROCESS) { - if ((stat = lock_inter(lock)) != APR_SUCCESS) { - return stat; - } - } + if ((stat = _lock(lock)) != APR_SUCCESS) + return stat; break; + case APR_READWRITE: return APR_ENOTIMPL; } @@ -147,7 +203,7 @@ apr_status_t apr_lock_release(apr_lock_t *lock) { apr_status_t stat; - if (lock->owner == apr_os_thread_current()) { + if (lock->owner_ref > 0 && lock->owner == apr_os_thread_current()) { lock->owner_ref--; if (lock->owner_ref > 0) return APR_SUCCESS; @@ -156,16 +212,8 @@ apr_status_t apr_lock_release(apr_lock_t *lock) switch (lock->type) { case APR_MUTEX: - if (lock->scope != APR_CROSS_PROCESS) { - if ((stat = unlock_intra(lock)) != APR_SUCCESS) { - return stat; - } - } - if (lock->scope != APR_INTRAPROCESS) { - if ((stat = unlock_inter(lock)) != APR_SUCCESS) { - return stat; - } - } + if ((stat = _unlock(lock)) != APR_SUCCESS) + return stat; break; case APR_READWRITE: return APR_ENOTIMPL; @@ -184,16 +232,8 @@ apr_status_t apr_lock_destroy(apr_lock_t *lock) switch (lock->type) { case APR_MUTEX: - if (lock->scope != APR_CROSS_PROCESS) { - if ((stat = destroy_intra_lock(lock)) != APR_SUCCESS) { - return stat; - } - } - if (lock->scope != APR_INTRAPROCESS) { - if ((stat = destroy_inter_lock(lock)) != APR_SUCCESS) { - return stat; - } - } + if ((stat = _destroy_lock(lock)) != APR_SUCCESS) + return stat; break; case APR_READWRITE: return APR_ENOTIMPL; @@ -203,14 +243,8 @@ apr_status_t apr_lock_destroy(apr_lock_t *lock) } apr_status_t apr_lock_child_init(apr_lock_t **lock, const char *fname, - apr_pool_t *pool) + apr_pool_t *pool) { - apr_status_t stat; - if ((*lock)->scope != APR_CROSS_PROCESS) { - if ((stat = child_init_lock(lock, pool, fname)) != APR_SUCCESS) { - return stat; - } - } return APR_SUCCESS; } @@ -227,10 +261,8 @@ apr_status_t apr_lock_data_set(apr_lock_t *lock, void *data, const char *key, apr_status_t apr_os_lock_get(apr_os_lock_t *oslock, apr_lock_t *lock) { - oslock->sem_interproc = lock->sem_interproc; - oslock->sem_intraproc = lock->sem_intraproc; - oslock->ben_interproc = lock->ben_interproc; - oslock->ben_intraproc = lock->ben_intraproc; + oslock->sem = lock->sem; + oslock->ben = lock->ben; return APR_SUCCESS; } @@ -244,11 +276,9 @@ apr_status_t apr_os_lock_put(apr_lock_t **lock, apr_os_lock_t *thelock, (*lock) = (apr_lock_t *)apr_pcalloc(pool, sizeof(apr_lock_t)); (*lock)->pool = pool; } - (*lock)->sem_interproc = thelock->sem_interproc; - (*lock)->ben_interproc = thelock->ben_interproc; + (*lock)->sem = thelock->sem; + (*lock)->ben = thelock->ben; - (*lock)->sem_intraproc = thelock->sem_intraproc; - (*lock)->ben_intraproc = thelock->ben_intraproc; return APR_SUCCESS; } |