proc_mutex.c (apr-1.6.5.tar.bz2) | : | proc_mutex.c (apr-1.7.0.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 30 | skipping to change at line 30 | |||
#include "apr_arch_proc_mutex.h" | #include "apr_arch_proc_mutex.h" | |||
#include "apr_strings.h" | #include "apr_strings.h" | |||
#include "apr_portable.h" | #include "apr_portable.h" | |||
static apr_status_t _proc_mutex_cleanup(void * data) | static apr_status_t _proc_mutex_cleanup(void * data) | |||
{ | { | |||
apr_proc_mutex_t *lock = (apr_proc_mutex_t*)data; | apr_proc_mutex_t *lock = (apr_proc_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_proc_mutex_create(apr_proc_mutex_t **mutex, | APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **mutex, | |||
const char *fname, | const char *fname, | |||
apr_lockmech_e mech, | apr_lockmech_e mech, | |||
apr_pool_t *pool) | apr_pool_t *pool) | |||
{ | { | |||
apr_proc_mutex_t *new; | apr_proc_mutex_t *new; | |||
apr_status_t stat = APR_SUCCESS; | apr_status_t stat = APR_SUCCESS; | |||
if (mech != APR_LOCK_DEFAULT) { | if (mech != APR_LOCK_DEFAULT && mech != APR_LOCK_DEFAULT_TIMED) { | |||
return APR_ENOTIMPL; | return APR_ENOTIMPL; | |||
} | } | |||
new = (apr_proc_mutex_t *)apr_pcalloc(pool, sizeof(apr_proc_mutex_t)); | new = (apr_proc_mutex_t *)apr_pcalloc(pool, sizeof(apr_proc_mutex_t)); | |||
if (new == NULL){ | if (new == NULL){ | |||
return APR_ENOMEM; | return APR_ENOMEM; | |||
} | } | |||
if ((stat = create_sem(0, "APR_Lock")) < B_NO_ERROR) { | if ((stat = create_sem(0, "APR_Lock")) < B_NO_ERROR) { | |||
_proc_mutex_cleanup(new); | _proc_mutex_cleanup(new); | |||
skipping to change at line 85 | skipping to change at line 85 | |||
const char *fname, | const char *fname, | |||
apr_pool_t *pool) | apr_pool_t *pool) | |||
{ | { | |||
return APR_SUCCESS; | return APR_SUCCESS; | |||
} | } | |||
APR_DECLARE(apr_status_t) apr_proc_mutex_lock(apr_proc_mutex_t *mutex) | APR_DECLARE(apr_status_t) apr_proc_mutex_lock(apr_proc_mutex_t *mutex) | |||
{ | { | |||
int32 stat; | int32 stat; | |||
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) { | |||
atomic_add(&mutex->LockCount, -1); | atomic_add(&mutex->LockCount, -1); | |||
return stat; | return stat; | |||
} | } | |||
} | } | |||
return APR_SUCCESS; | return APR_SUCCESS; | |||
} | } | |||
APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex) | APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex) | |||
{ | { | |||
return APR_ENOTIMPL; | int32 stat; | |||
if (atomic_add(&mutex->LockCount, 1) > 0) { | ||||
stat = acquire_sem_etc(mutex->Lock, 1, 0, 0); | ||||
if (stat < B_NO_ERROR) { | ||||
atomic_add(&mutex->LockCount, -1); | ||||
if (stat == B_WOULD_BLOCK) { | ||||
stat = APR_EBUSY; | ||||
} | ||||
return stat; | ||||
} | ||||
} | ||||
return APR_SUCCESS; | ||||
} | ||||
APR_DECLARE(apr_status_t) apr_proc_mutex_timedlock(apr_proc_mutex_t *mutex, | ||||
apr_interval_time_t timeout) | ||||
{ | ||||
int32 stat; | ||||
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; | ||||
} | ||||
} | ||||
return APR_SUCCESS; | ||||
} | } | |||
APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex) | APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex) | |||
{ | { | |||
int32 stat; | int32 stat; | |||
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; | |||
} | } | |||
} | } | |||
return APR_SUCCESS; | return APR_SUCCESS; | |||
} | } | |||
APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex) | APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex) | |||
{ | { | |||
skipping to change at line 180 | skipping to change at line 216 | |||
APR_DECLARE(apr_status_t) apr_os_proc_mutex_put_ex(apr_proc_mutex_t **pmutex, | APR_DECLARE(apr_status_t) apr_os_proc_mutex_put_ex(apr_proc_mutex_t **pmutex, | |||
apr_os_proc_mutex_t *ospmutex, | apr_os_proc_mutex_t *ospmutex, | |||
apr_lockmech_e mech, | apr_lockmech_e mech, | |||
int register_cleanup, | int register_cleanup, | |||
apr_pool_t *pool) | apr_pool_t *pool) | |||
{ | { | |||
if (pool == NULL) { | if (pool == NULL) { | |||
return APR_ENOPOOL; | return APR_ENOPOOL; | |||
} | } | |||
if (mech != APR_LOCK_DEFAULT) { | if (mech != APR_LOCK_DEFAULT && mech != APR_LOCK_DEFAULT_TIMED) { | |||
return APR_ENOTIMPL; | return APR_ENOTIMPL; | |||
} | } | |||
if ((*pmutex) == NULL) { | if ((*pmutex) == NULL) { | |||
(*pmutex) = (apr_proc_mutex_t *)apr_pcalloc(pool, sizeof(apr_proc_mutex_ t)); | (*pmutex) = (apr_proc_mutex_t *)apr_pcalloc(pool, sizeof(apr_proc_mutex_ t)); | |||
(*pmutex)->pool = pool; | (*pmutex)->pool = pool; | |||
} | } | |||
(*pmutex)->Lock = ospmutex->sem; | (*pmutex)->Lock = ospmutex->sem; | |||
(*pmutex)->LockCount = ospmutex->ben; | (*pmutex)->LockCount = ospmutex->ben; | |||
End of changes. 7 change blocks. | ||||
16 lines changed or deleted | 52 lines changed or added |