wrapped all pthread_rwlock_t in profilable rwlock_t

This commit is contained in:
Martin Willi
2008-11-05 16:12:54 +00:00
parent c1be64eaff
commit 27ed987ef7
8 changed files with 122 additions and 111 deletions
+15 -5
View File
@@ -15,17 +15,18 @@
* $Id$
*/
#include "mutex.h"
#include <library.h>
#include <debug.h>
#define _GNU_SOURCE
#include <pthread.h>
#include <sys/time.h>
#include <stdint.h>
#include <time.h>
#include <errno.h>
#include "mutex.h"
#include <library.h>
#include <debug.h>
typedef struct private_mutex_t private_mutex_t;
typedef struct private_r_mutex_t private_r_mutex_t;
typedef struct private_condvar_t private_condvar_t;
@@ -440,6 +441,14 @@ static void write_lock(private_rwlock_t *this)
profiler_end(&this->profile);
}
/**
* Implementation of rwlock_t.try_write_lock
*/
static bool try_write_lock(private_rwlock_t *this)
{
return pthread_rwlock_trywrlock(&this->rwlock) == 0;
}
/**
* Implementation of rwlock_t.unlock
*/
@@ -472,6 +481,7 @@ rwlock_t *rwlock_create(rwlock_type_t type)
this->public.read_lock = (void(*)(rwlock_t*))read_lock;
this->public.write_lock = (void(*)(rwlock_t*))write_lock;
this->public.try_write_lock = (bool(*)(rwlock_t*))try_write_lock;
this->public.unlock = (void(*)(rwlock_t*))rw_unlock;
this->public.destroy = (void(*)(rwlock_t*))rw_destroy;
+9
View File
@@ -129,6 +129,15 @@ struct rwlock_t {
*/
void (*write_lock)(rwlock_t *this);
/**
* Try to acquire the write lock.
*
* Never blocks, but returns FALSE if the lock was already occupied.
*
* @return TRUE if lock acquired
*/
bool (*try_write_lock)(rwlock_t *this);
/**
* Release any acquired lock.
*/