"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "locks/beos/thread_mutex.c" between
apr-1.6.5.tar.bz2 and apr-1.7.0.tar.bz2

About: APR (Apache Portable Runtime) project offers software libraries that provide a predictable and consistent interface to underlying platform-specific implementations (APR core library).

thread_mutex.c  (apr-1.6.5.tar.bz2):thread_mutex.c  (apr-1.7.0.tar.bz2)
skipping to change at line 30 skipping to change at line 30
#include "apr_arch_thread_mutex.h" #include "apr_arch_thread_mutex.h"
#include "apr_strings.h" #include "apr_strings.h"
#include "apr_portable.h" #include "apr_portable.h"
static apr_status_t _thread_mutex_cleanup(void * data) static apr_status_t _thread_mutex_cleanup(void * data)
{ {
apr_thread_mutex_t *lock = (apr_thread_mutex_t*)data; apr_thread_mutex_t *lock = (apr_thread_mutex_t*)data;
if (lock->LockCount != 0) { if (lock->LockCount != 0) {
/* we're still locked... */ /* we're still locked... */
while (atomic_add(&lock->LockCount , -1) > 1){ while (atomic_add(&lock->LockCount , -1) > 1){
/* OK we had more than one person waiting on the lock so /* OK we had more than one person waiting on the lock so
* the sem is also locked. Release it until we have no more * the sem is also locked. Release it until we have no more
* locks left. * locks left.
*/ */
release_sem (lock->Lock); release_sem (lock->Lock);
} }
} }
delete_sem(lock->Lock); delete_sem(lock->Lock);
return APR_SUCCESS; return APR_SUCCESS;
} }
APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex, APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
unsigned int flags, unsigned int flags,
apr_pool_t *pool) apr_pool_t *pool)
{ {
apr_thread_mutex_t *new_m; apr_thread_mutex_t *new_m;
skipping to change at line 94 skipping to change at line 94
APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex) APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
{ {
int32 stat; int32 stat;
thread_id me = find_thread(NULL); thread_id me = find_thread(NULL);
if (mutex->nested && mutex->owner == me) { if (mutex->nested && mutex->owner == me) {
mutex->owner_ref++; mutex->owner_ref++;
return APR_SUCCESS; return APR_SUCCESS;
} }
if (atomic_add(&mutex->LockCount, 1) > 0) { if (atomic_add(&mutex->LockCount, 1) > 0) {
if ((stat = acquire_sem(mutex->Lock)) < B_NO_ERROR) { if ((stat = acquire_sem(mutex->Lock)) < B_NO_ERROR) {
/* Oh dear, acquire_sem failed!! */ /* Oh dear, acquire_sem failed!! */
atomic_add(&mutex->LockCount, -1); atomic_add(&mutex->LockCount, -1);
return stat; return stat;
} }
} }
mutex->owner = me; mutex->owner = me;
mutex->owner_ref = 1; mutex->owner_ref = 1;
return APR_SUCCESS; return APR_SUCCESS;
} }
APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex) APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
{ {
return APR_ENOTIMPL; int32 stat;
thread_id me = find_thread(NULL);
if (mutex->nested && mutex->owner == me) {
mutex->owner_ref++;
return APR_SUCCESS;
}
if (atomic_add(&mutex->LockCount, 1) > 0) {
if ((stat = acquire_sem_etc(mutex->Lock, 1, 0, 0)) < B_NO_ERROR) {
atomic_add(&mutex->LockCount, -1);
if (stat == B_WOULD_BLOCK) {
stat = APR_EBUSY;
}
return stat;
}
}
mutex->owner = me;
mutex->owner_ref = 1;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex,
apr_interval_time_t timeout)
{
int32 stat;
thread_id me = find_thread(NULL);
if (mutex->nested && mutex->owner == me) {
mutex->owner_ref++;
return APR_SUCCESS;
}
if (atomic_add(&mutex->LockCount, 1) > 0) {
if (timeout <= 0) {
stat = B_TIMED_OUT;
}
else {
stat = acquire_sem_etc(mutex->Lock, 1, B_RELATIVE_TIMEOUT,
timeout);
}
if (stat < B_NO_ERROR) {
atomic_add(&mutex->LockCount, -1);
if (stat == B_TIMED_OUT) {
stat = APR_TIMEUP;
}
return stat;
}
}
mutex->owner = me;
mutex->owner_ref = 1;
return APR_SUCCESS;
} }
APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex) APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
{ {
int32 stat; int32 stat;
if (mutex->nested && mutex->owner == find_thread(NULL)) { if (mutex->nested && mutex->owner == find_thread(NULL)) {
mutex->owner_ref--; mutex->owner_ref--;
if (mutex->owner_ref > 0) if (mutex->owner_ref > 0)
return APR_SUCCESS; return APR_SUCCESS;
} }
if (atomic_add(&mutex->LockCount, -1) > 1) { if (atomic_add(&mutex->LockCount, -1) > 1) {
if ((stat = release_sem(mutex->Lock)) < B_NO_ERROR) { if ((stat = release_sem(mutex->Lock)) < B_NO_ERROR) {
atomic_add(&mutex->LockCount, 1); atomic_add(&mutex->LockCount, 1);
return stat; return stat;
} }
} }
mutex->owner = -1; mutex->owner = -1;
mutex->owner_ref = 0; mutex->owner_ref = 0;
return APR_SUCCESS; return APR_SUCCESS;
 End of changes. 6 change blocks. 
14 lines changed or deleted 69 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)