#include "apr_arch_thread_rwlock.h"
#include "apr_private.h"
#if APR_HAS_THREADS
#ifdef HAVE_PTHREAD_RWLOCKS
static apr_status_t thread_rwlock_cleanup(void *data)
{
apr_thread_rwlock_t *rwlock = (apr_thread_rwlock_t *)data;
apr_status_t stat;
stat = pthread_rwlock_destroy(&rwlock->rwlock);
#ifdef HAVE_ZOS_PTHREADS
if (stat) {
stat = errno;
}
#endif
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
apr_pool_t *pool)
{
apr_thread_rwlock_t *new_rwlock;
apr_status_t stat;
new_rwlock = apr_palloc(pool, sizeof(apr_thread_rwlock_t));
new_rwlock->pool = pool;
if ((stat = pthread_rwlock_init(&new_rwlock->rwlock, NULL))) {
#ifdef HAVE_ZOS_PTHREADS
stat = errno;
#endif
return stat;
}
apr_pool_cleanup_register(new_rwlock->pool,
(void *)new_rwlock, thread_rwlock_cleanup,
apr_pool_cleanup_null);
*rwlock = new_rwlock;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
stat = pthread_rwlock_rdlock(&rwlock->rwlock);
#ifdef HAVE_ZOS_PTHREADS
if (stat) {
stat = errno;
}
#endif
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
stat = pthread_rwlock_tryrdlock(&rwlock->rwlock);
#ifdef HAVE_ZOS_PTHREADS
if (stat) {
stat = errno;
}
#endif
if (stat == EBUSY)
stat = APR_EBUSY;
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
stat = pthread_rwlock_wrlock(&rwlock->rwlock);
#ifdef HAVE_ZOS_PTHREADS
if (stat) {
stat = errno;
}
#endif
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
stat = pthread_rwlock_trywrlock(&rwlock->rwlock);
#ifdef HAVE_ZOS_PTHREADS
if (stat) {
stat = errno;
}
#endif
if (stat == EBUSY)
stat = APR_EBUSY;
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
stat = pthread_rwlock_unlock(&rwlock->rwlock);
#ifdef HAVE_ZOS_PTHREADS
if (stat) {
stat = errno;
}
#endif
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
{
return apr_pool_cleanup_run(rwlock->pool, rwlock, thread_rwlock_cleanup);
}
#else
APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
apr_pool_t *pool)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
#endif
APR_POOL_IMPLEMENT_ACCESSOR(thread_rwlock)
#endif