Migrated rwlock_t to INIT/METHOD macros.
This commit is contained in:
@@ -87,10 +87,8 @@ struct private_rwlock_t {
|
|||||||
|
|
||||||
#ifdef HAVE_PTHREAD_RWLOCK_INIT
|
#ifdef HAVE_PTHREAD_RWLOCK_INIT
|
||||||
|
|
||||||
/**
|
METHOD(rwlock_t, read_lock, void,
|
||||||
* Implementation of rwlock_t.read_lock
|
private_rwlock_t *this)
|
||||||
*/
|
|
||||||
static void read_lock(private_rwlock_t *this)
|
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@@ -103,10 +101,8 @@ static void read_lock(private_rwlock_t *this)
|
|||||||
profiler_end(&this->profile);
|
profiler_end(&this->profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(rwlock_t, write_lock, void,
|
||||||
* Implementation of rwlock_t.write_lock
|
private_rwlock_t *this)
|
||||||
*/
|
|
||||||
static void write_lock(private_rwlock_t *this)
|
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@@ -119,18 +115,14 @@ static void write_lock(private_rwlock_t *this)
|
|||||||
profiler_end(&this->profile);
|
profiler_end(&this->profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(rwlock_t, try_write_lock, bool,
|
||||||
* Implementation of rwlock_t.try_write_lock
|
private_rwlock_t *this)
|
||||||
*/
|
|
||||||
static bool try_write_lock(private_rwlock_t *this)
|
|
||||||
{
|
{
|
||||||
return pthread_rwlock_trywrlock(&this->rwlock) == 0;
|
return pthread_rwlock_trywrlock(&this->rwlock) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(rwlock_t, unlock, void,
|
||||||
* Implementation of rwlock_t.unlock
|
private_rwlock_t *this)
|
||||||
*/
|
|
||||||
static void rw_unlock(private_rwlock_t *this)
|
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@@ -141,10 +133,8 @@ static void rw_unlock(private_rwlock_t *this)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(rwlock_t, destroy, void,
|
||||||
* Implementation of rwlock_t.destroy
|
private_rwlock_t *this)
|
||||||
*/
|
|
||||||
static void rw_destroy(private_rwlock_t *this)
|
|
||||||
{
|
{
|
||||||
pthread_rwlock_destroy(&this->rwlock);
|
pthread_rwlock_destroy(&this->rwlock);
|
||||||
profiler_cleanup(&this->profile);
|
profiler_cleanup(&this->profile);
|
||||||
@@ -161,13 +151,17 @@ rwlock_t *rwlock_create(rwlock_type_t type)
|
|||||||
case RWLOCK_TYPE_DEFAULT:
|
case RWLOCK_TYPE_DEFAULT:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
private_rwlock_t *this = malloc_thing(private_rwlock_t);
|
private_rwlock_t *this;
|
||||||
|
|
||||||
this->public.read_lock = (void(*)(rwlock_t*))read_lock;
|
INIT(this,
|
||||||
this->public.write_lock = (void(*)(rwlock_t*))write_lock;
|
.public = {
|
||||||
this->public.try_write_lock = (bool(*)(rwlock_t*))try_write_lock;
|
.read_lock = _read_lock,
|
||||||
this->public.unlock = (void(*)(rwlock_t*))rw_unlock;
|
.write_lock = _write_lock,
|
||||||
this->public.destroy = (void(*)(rwlock_t*))rw_destroy;
|
.try_write_lock = _try_write_lock,
|
||||||
|
.unlock = _unlock,
|
||||||
|
.destroy = _destroy,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
pthread_rwlock_init(&this->rwlock, NULL);
|
pthread_rwlock_init(&this->rwlock, NULL);
|
||||||
profiler_init(&this->profile);
|
profiler_init(&this->profile);
|
||||||
@@ -200,10 +194,8 @@ rwlock_t *rwlock_create(rwlock_type_t type)
|
|||||||
* checked or enforced so behave yourself to prevent deadlocks).
|
* checked or enforced so behave yourself to prevent deadlocks).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
METHOD(rwlock_t, read_lock, void,
|
||||||
* Implementation of rwlock_t.read_lock
|
private_rwlock_t *this)
|
||||||
*/
|
|
||||||
static void read_lock(private_rwlock_t *this)
|
|
||||||
{
|
{
|
||||||
profiler_start(&this->profile);
|
profiler_start(&this->profile);
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
@@ -216,10 +208,8 @@ static void read_lock(private_rwlock_t *this)
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(rwlock_t, write_lock, void,
|
||||||
* Implementation of rwlock_t.write_lock
|
private_rwlock_t *this)
|
||||||
*/
|
|
||||||
static void write_lock(private_rwlock_t *this)
|
|
||||||
{
|
{
|
||||||
profiler_start(&this->profile);
|
profiler_start(&this->profile);
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
@@ -234,10 +224,8 @@ static void write_lock(private_rwlock_t *this)
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(rwlock_t, try_write_lock, bool,
|
||||||
* Implementation of rwlock_t.try_write_lock
|
private_rwlock_t *this)
|
||||||
*/
|
|
||||||
static bool try_write_lock(private_rwlock_t *this)
|
|
||||||
{
|
{
|
||||||
bool res = FALSE;
|
bool res = FALSE;
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
@@ -250,10 +238,8 @@ static bool try_write_lock(private_rwlock_t *this)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(rwlock_t, unlock, void,
|
||||||
* Implementation of rwlock_t.unlock
|
private_rwlock_t *this)
|
||||||
*/
|
|
||||||
static void rw_unlock(private_rwlock_t *this)
|
|
||||||
{
|
{
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
if (this->writer == pthread_self())
|
if (this->writer == pthread_self())
|
||||||
@@ -279,10 +265,8 @@ static void rw_unlock(private_rwlock_t *this)
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(rwlock_t, destroy, void,
|
||||||
* Implementation of rwlock_t.destroy
|
private_rwlock_t *this)
|
||||||
*/
|
|
||||||
static void rw_destroy(private_rwlock_t *this)
|
|
||||||
{
|
{
|
||||||
this->mutex->destroy(this->mutex);
|
this->mutex->destroy(this->mutex);
|
||||||
this->writers->destroy(this->writers);
|
this->writers->destroy(this->writers);
|
||||||
@@ -301,20 +285,20 @@ rwlock_t *rwlock_create(rwlock_type_t type)
|
|||||||
case RWLOCK_TYPE_DEFAULT:
|
case RWLOCK_TYPE_DEFAULT:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
private_rwlock_t *this = malloc_thing(private_rwlock_t);
|
private_rwlock_t *this;
|
||||||
|
|
||||||
this->public.read_lock = (void(*)(rwlock_t*))read_lock;
|
INIT(this,
|
||||||
this->public.write_lock = (void(*)(rwlock_t*))write_lock;
|
.public = {
|
||||||
this->public.try_write_lock = (bool(*)(rwlock_t*))try_write_lock;
|
.read_lock = _read_lock,
|
||||||
this->public.unlock = (void(*)(rwlock_t*))rw_unlock;
|
.write_lock = _write_lock,
|
||||||
this->public.destroy = (void(*)(rwlock_t*))rw_destroy;
|
.try_write_lock = _try_write_lock,
|
||||||
|
.unlock = _unlock,
|
||||||
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
|
.destroy = _destroy,
|
||||||
this->writers = condvar_create(CONDVAR_TYPE_DEFAULT);
|
},
|
||||||
this->readers = condvar_create(CONDVAR_TYPE_DEFAULT);
|
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
|
||||||
this->waiting_writers = 0;
|
.writers = condvar_create(CONDVAR_TYPE_DEFAULT),
|
||||||
this->reader_count = 0;
|
.readers = condvar_create(CONDVAR_TYPE_DEFAULT),
|
||||||
this->writer = 0;
|
);
|
||||||
|
|
||||||
profiler_init(&this->profile);
|
profiler_init(&this->profile);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user