wrapped all pthread_rwlock_t in profilable rwlock_t
This commit is contained in:
@@ -15,14 +15,11 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <pthread.h>
|
||||
|
||||
#include "fetcher_manager.h"
|
||||
|
||||
#include <debug.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <utils/mutex.h>
|
||||
#include <utils/linked_list.h>
|
||||
|
||||
typedef struct private_fetcher_manager_t private_fetcher_manager_t;
|
||||
|
||||
@@ -44,7 +41,7 @@ struct private_fetcher_manager_t {
|
||||
/**
|
||||
* read write lock to list
|
||||
*/
|
||||
pthread_rwlock_t lock;
|
||||
rwlock_t *lock;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@@ -74,7 +71,7 @@ static status_t fetch(private_fetcher_manager_t *this,
|
||||
entry_t *entry;
|
||||
bool capable = FALSE;
|
||||
|
||||
pthread_rwlock_rdlock(&this->lock);
|
||||
this->lock->read_lock(this->lock);
|
||||
enumerator = this->fetchers->create_enumerator(this->fetchers);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
{
|
||||
@@ -132,7 +129,7 @@ static status_t fetch(private_fetcher_manager_t *this,
|
||||
break;
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
pthread_rwlock_unlock(&this->lock);
|
||||
this->lock->unlock(this->lock);
|
||||
if (!capable)
|
||||
{
|
||||
DBG1("unable to fetch from %s, no capable fetcher found", url);
|
||||
@@ -151,9 +148,9 @@ static void add_fetcher(private_fetcher_manager_t *this,
|
||||
entry->url = strdup(url);
|
||||
entry->create = create;
|
||||
|
||||
pthread_rwlock_wrlock(&this->lock);
|
||||
this->lock->write_lock(this->lock);
|
||||
this->fetchers->insert_last(this->fetchers, entry);
|
||||
pthread_rwlock_unlock(&this->lock);
|
||||
this->lock->unlock(this->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,7 +162,7 @@ static void remove_fetcher(private_fetcher_manager_t *this,
|
||||
enumerator_t *enumerator;
|
||||
entry_t *entry;
|
||||
|
||||
pthread_rwlock_wrlock(&this->lock);
|
||||
this->lock->write_lock(this->lock);
|
||||
enumerator = this->fetchers->create_enumerator(this->fetchers);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
{
|
||||
@@ -176,7 +173,7 @@ static void remove_fetcher(private_fetcher_manager_t *this,
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
pthread_rwlock_unlock(&this->lock);
|
||||
this->lock->unlock(this->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,7 +182,7 @@ static void remove_fetcher(private_fetcher_manager_t *this,
|
||||
static void destroy(private_fetcher_manager_t *this)
|
||||
{
|
||||
this->fetchers->destroy_function(this->fetchers, (void*)entry_destroy);
|
||||
pthread_rwlock_destroy(&this->lock);
|
||||
this->lock->destroy(this->lock);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@@ -202,7 +199,7 @@ fetcher_manager_t *fetcher_manager_create()
|
||||
this->public.destroy = (void(*)(fetcher_manager_t*))destroy;
|
||||
|
||||
this->fetchers = linked_list_create();
|
||||
pthread_rwlock_init(&this->lock, NULL);
|
||||
this->lock = rwlock_create(RWLOCK_DEFAULT);
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user