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
+19 -20
View File
@@ -15,12 +15,10 @@
* $Id$
*/
#define _GNU_SOURCE
#include <pthread.h>
#include "nm_creds.h"
#include <daemon.h>
#include <utils/mutex.h>
typedef struct private_nm_creds_t private_nm_creds_t;
@@ -62,7 +60,7 @@ struct private_nm_creds_t {
/**
* read/write lock
*/
pthread_rwlock_t lock;
rwlock_t *lock;
};
/**
@@ -91,10 +89,10 @@ static enumerator_t *create_usercert_enumerator(private_nm_creds_t *this,
}
public->destroy(public);
}
pthread_rwlock_rdlock(&this->lock);
this->lock->read_lock(this->lock);
return enumerator_create_cleaner(
enumerator_create_single(this->usercert, NULL),
(void*)pthread_rwlock_unlock, &this->lock);
(void*)this->lock->unlock, this->lock);
}
/**
@@ -138,9 +136,9 @@ static enumerator_t* create_cert_enumerator(private_nm_creds_t *this,
}
public->destroy(public);
}
pthread_rwlock_rdlock(&this->lock);
this->lock->read_lock(this->lock);
return enumerator_create_cleaner(enumerator_create_single(this->cert, NULL),
(void*)pthread_rwlock_unlock, &this->lock);
(void*)this->lock->unlock, this->lock);
}
/**
@@ -167,9 +165,9 @@ static enumerator_t* create_private_enumerator(private_nm_creds_t *this,
return NULL;
}
}
pthread_rwlock_rdlock(&this->lock);
this->lock->read_lock(this->lock);
return enumerator_create_cleaner(enumerator_create_single(this->key, NULL),
(void*)pthread_rwlock_unlock, &this->lock);
(void*)this->lock->unlock, this->lock);
}
/**
@@ -205,7 +203,8 @@ static bool shared_enumerate(shared_enumerator_t *this, shared_key_t **key,
static void shared_destroy(shared_enumerator_t *this)
{
this->key->destroy(this->key);
pthread_rwlock_unlock(&this->this->lock);
this->lock->destroy(this->lock);
this->this->lock->unlock(this->this->lock);
free(this);
}
/**
@@ -235,7 +234,7 @@ static enumerator_t* create_shared_enumerator(private_nm_creds_t *this,
enumerator->public.destroy = (void*)shared_destroy;
enumerator->this = this;
enumerator->done = FALSE;
pthread_rwlock_rdlock(&this->lock);
this->lock->read_lock(this->lock);
enumerator->key = shared_key_create(type,
chunk_clone(chunk_create(this->pass,
strlen(this->pass))));
@@ -247,10 +246,10 @@ static enumerator_t* create_shared_enumerator(private_nm_creds_t *this,
*/
static void set_certificate(private_nm_creds_t *this, certificate_t *cert)
{
pthread_rwlock_wrlock(&this->lock);
this->lock->write_lock(this->lock);
DESTROY_IF(this->cert);
this->cert = cert;
pthread_rwlock_unlock(&this->lock);
this->lock->unlock(this->lock);
}
/**
@@ -259,14 +258,14 @@ static void set_certificate(private_nm_creds_t *this, certificate_t *cert)
static void set_username_password(private_nm_creds_t *this, identification_t *id,
char *password)
{
pthread_rwlock_wrlock(&this->lock);
this->lock->write_lock(this->lock);
DESTROY_IF(this->user);
/* for EAP authentication, we use always use ID_EAP type */
this->user = identification_create_from_encoding(ID_EAP,
id->get_encoding(id));
free(this->pass);
this->pass = password ? strdup(password) : NULL;
pthread_rwlock_unlock(&this->lock);
this->lock->unlock(this->lock);
}
/**
@@ -275,12 +274,12 @@ static void set_username_password(private_nm_creds_t *this, identification_t *id
static void set_cert_and_key(private_nm_creds_t *this, certificate_t *cert,
private_key_t *key)
{
pthread_rwlock_wrlock(&this->lock);
this->lock->write_lock(this->lock);
DESTROY_IF(this->key);
DESTROY_IF(this->usercert);
this->key = key;
this->usercert = cert;
pthread_rwlock_unlock(&this->lock);
this->lock->unlock(this->lock);
}
/**
@@ -306,7 +305,7 @@ static void clear(private_nm_creds_t *this)
static void destroy(private_nm_creds_t *this)
{
clear(this);
pthread_rwlock_destroy(&this->lock);
this->lock->destroy(this->lock);
free(this);
}
@@ -328,7 +327,7 @@ nm_creds_t *nm_creds_create()
this->public.clear = (void(*)(nm_creds_t*))clear;
this->public.destroy = (void(*)(nm_creds_t*))destroy;
pthread_rwlock_init(&this->lock, NULL);
this->lock = rwlock_create(RWLOCK_DEFAULT);
this->cert = NULL;
this->user = NULL;
+14 -16
View File
@@ -16,12 +16,10 @@
* $Id$
*/
#define _GNU_SOURCE
#include <pthread.h>
#include "stroke_ca.h"
#include "stroke_cred.h"
#include <utils/mutex.h>
#include <utils/linked_list.h>
#include <crypto/hashers/hasher.h>
@@ -42,7 +40,7 @@ struct private_stroke_ca_t {
/**
* read-write lock to lists
*/
pthread_rwlock_t lock;
rwlock_t *lock;
/**
* list of starters CA sections and its certificates (ca_section_t)
@@ -136,7 +134,7 @@ typedef struct {
*/
static void cdp_data_destroy(cdp_data_t *data)
{
pthread_rwlock_unlock(&data->this->lock);
data->this->lock->unlock(data->this->lock);
free(data);
}
@@ -236,7 +234,7 @@ static enumerator_t *create_cdp_enumerator(private_stroke_ca_t *this,
data->type = type;
data->id = id;
pthread_rwlock_rdlock(&this->lock);
this->lock->read_lock(this->lock);
return enumerator_create_nested(this->sections->create_enumerator(this->sections),
(type == CERT_X509) ? (void*)create_inner_cdp_hashandurl : (void*)create_inner_cdp,
data, (void*)cdp_data_destroy);
@@ -278,9 +276,9 @@ static void add(private_stroke_ca_t *this, stroke_msg_t *msg)
{
ca->certuribase = strdup(msg->add_ca.certuribase);
}
pthread_rwlock_wrlock(&this->lock);
this->lock->write_lock(this->lock);
this->sections->insert_last(this->sections, ca);
pthread_rwlock_unlock(&this->lock);
this->lock->unlock(this->lock);
DBG1(DBG_CFG, "added ca '%s'", msg->add_ca.name);
}
}
@@ -293,7 +291,7 @@ static void del(private_stroke_ca_t *this, stroke_msg_t *msg)
enumerator_t *enumerator;
ca_section_t *ca = NULL;
pthread_rwlock_wrlock(&this->lock);
this->lock->write_lock(this->lock);
enumerator = this->sections->create_enumerator(this->sections);
while (enumerator->enumerate(enumerator, &ca))
{
@@ -305,7 +303,7 @@ static void del(private_stroke_ca_t *this, stroke_msg_t *msg)
ca = NULL;
}
enumerator->destroy(enumerator);
pthread_rwlock_unlock(&this->lock);
this->lock->unlock(this->lock);
if (ca == NULL)
{
DBG1(DBG_CFG, "no ca named '%s' found\n", msg->del_ca.name);
@@ -356,7 +354,7 @@ static void check_for_hash_and_url(private_stroke_ca_t *this, certificate_t* cer
return;
}
pthread_rwlock_wrlock(&this->lock);
this->lock->write_lock(this->lock);
enumerator = this->sections->create_enumerator(this->sections);
while (enumerator->enumerate(enumerator, (void**)&section))
{
@@ -372,7 +370,7 @@ static void check_for_hash_and_url(private_stroke_ca_t *this, certificate_t* cer
}
}
enumerator->destroy(enumerator);
pthread_rwlock_unlock(&this->lock);
this->lock->unlock(this->lock);
hasher->destroy(hasher);
}
@@ -386,7 +384,7 @@ static void list(private_stroke_ca_t *this, stroke_msg_t *msg, FILE *out)
ca_section_t *section;
enumerator_t *enumerator;
pthread_rwlock_rdlock(&this->lock);
this->lock->read_lock(this->lock);
enumerator = this->sections->create_enumerator(this->sections);
while (enumerator->enumerate(enumerator, (void**)&section))
{
@@ -419,7 +417,7 @@ static void list(private_stroke_ca_t *this, stroke_msg_t *msg, FILE *out)
}
}
enumerator->destroy(enumerator);
pthread_rwlock_unlock(&this->lock);
this->lock->unlock(this->lock);
}
/**
@@ -428,7 +426,7 @@ static void list(private_stroke_ca_t *this, stroke_msg_t *msg, FILE *out)
static void destroy(private_stroke_ca_t *this)
{
this->sections->destroy_function(this->sections, (void*)ca_section_destroy);
pthread_rwlock_destroy(&this->lock);
this->lock->destroy(this->lock);
free(this);
}
@@ -451,7 +449,7 @@ stroke_ca_t *stroke_ca_create(stroke_cred_t *cred)
this->public.destroy = (void(*)(stroke_ca_t*))destroy;
this->sections = linked_list_create();
pthread_rwlock_init(&this->lock, NULL);
this->lock = rwlock_create(RWLOCK_DEFAULT);
this->cred = cred;
return &this->public;
+18 -19
View File
@@ -15,8 +15,6 @@
* $Id$
*/
#define _GNU_SOURCE
#include <pthread.h>
#include <sys/stat.h>
#include <limits.h>
@@ -28,6 +26,7 @@
#include <credentials/certificates/ac.h>
#include <utils/linked_list.h>
#include <utils/lexparser.h>
#include <utils/mutex.h>
#include <asn1/pem.h>
#include <daemon.h>
@@ -73,7 +72,7 @@ struct private_stroke_cred_t {
/**
* read-write lock to lists
*/
pthread_rwlock_t lock;
rwlock_t *lock;
/**
* cache CRLs to disk?
@@ -94,7 +93,7 @@ typedef struct {
*/
static void id_data_destroy(id_data_t *data)
{
pthread_rwlock_unlock(&data->this->lock);
data->this->lock->unlock(data->this->lock);
free(data);
}
@@ -140,7 +139,7 @@ static enumerator_t* create_private_enumerator(private_stroke_cred_t *this,
data->this = this;
data->id = id;
pthread_rwlock_rdlock(&this->lock);
this->lock->read_lock(this->lock);
return enumerator_create_filter(this->private->create_enumerator(this->private),
(void*)private_filter, data,
(void*)id_data_destroy);
@@ -241,7 +240,7 @@ static enumerator_t* create_cert_enumerator(private_stroke_cred_t *this,
data->this = this;
data->id = id;
pthread_rwlock_rdlock(&this->lock);
this->lock->read_lock(this->lock);
return enumerator_create_filter(this->certs->create_enumerator(this->certs),
(cert == CERT_X509_CRL)? (void*)crl_filter : (void*)ac_filter,
data, (void*)id_data_destroy);
@@ -254,7 +253,7 @@ static enumerator_t* create_cert_enumerator(private_stroke_cred_t *this,
data->this = this;
data->id = id;
pthread_rwlock_rdlock(&this->lock);
this->lock->read_lock(this->lock);
return enumerator_create_filter(this->certs->create_enumerator(this->certs),
(void*)certs_filter, data,
(void*)id_data_destroy);
@@ -272,7 +271,7 @@ typedef struct {
*/
static void shared_data_destroy(shared_data_t *data)
{
pthread_rwlock_unlock(&data->this->lock);
data->this->lock->unlock(data->this->lock);
free(data);
}
@@ -324,7 +323,7 @@ static enumerator_t* create_shared_enumerator(private_stroke_cred_t *this,
data->me = me;
data->other = other;
data->type = type;
pthread_rwlock_rdlock(&this->lock);
this->lock->read_lock(this->lock);
return enumerator_create_filter(this->shared->create_enumerator(this->shared),
(void*)shared_filter, data,
(void*)shared_data_destroy);
@@ -339,7 +338,7 @@ static certificate_t* add_cert(private_stroke_cred_t *this, certificate_t *cert)
enumerator_t *enumerator;
bool new = TRUE;
pthread_rwlock_rdlock(&this->lock);
this->lock->read_lock(this->lock);
enumerator = this->certs->create_enumerator(this->certs);
while (enumerator->enumerate(enumerator, (void**)&current))
{
@@ -358,7 +357,7 @@ static certificate_t* add_cert(private_stroke_cred_t *this, certificate_t *cert)
{
this->certs->insert_last(this->certs, cert);
}
pthread_rwlock_unlock(&this->lock);
this->lock->unlock(this->lock);
return cert;
}
@@ -400,7 +399,7 @@ static bool add_crl(private_stroke_cred_t *this, crl_t* crl)
enumerator_t *enumerator;
bool new = TRUE, found = FALSE;
pthread_rwlock_wrlock(&this->lock);
this->lock->write_lock(this->lock);
enumerator = this->certs->create_enumerator(this->certs);
while (enumerator->enumerate(enumerator, (void**)&current))
{
@@ -448,7 +447,7 @@ static bool add_crl(private_stroke_cred_t *this, crl_t* crl)
{
this->certs->insert_last(this->certs, cert);
}
pthread_rwlock_unlock(&this->lock);
this->lock->unlock(this->lock);
return new;
}
@@ -459,9 +458,9 @@ static bool add_ac(private_stroke_cred_t *this, ac_t* ac)
{
certificate_t *cert = &ac->certificate;
pthread_rwlock_wrlock(&this->lock);
this->lock->write_lock(this->lock);
this->certs->insert_last(this->certs, cert);
pthread_rwlock_unlock(&this->lock);
this->lock->unlock(this->lock);
return TRUE;
}
@@ -698,7 +697,7 @@ static void load_secrets(private_stroke_cred_t *this)
fclose(fd);
src = chunk;
pthread_rwlock_wrlock(&this->lock);
this->lock->write_lock(this->lock);
while (this->shared->remove_last(this->shared,
(void**)&shared) == SUCCESS)
{
@@ -868,7 +867,7 @@ static void load_secrets(private_stroke_cred_t *this)
}
}
error:
pthread_rwlock_unlock(&this->lock);
this->lock->unlock(this->lock);
chunk_clear(&chunk);
}
@@ -949,7 +948,7 @@ static void destroy(private_stroke_cred_t *this)
this->certs->destroy_offset(this->certs, offsetof(certificate_t, destroy));
this->shared->destroy_offset(this->shared, offsetof(shared_key_t, destroy));
this->private->destroy_offset(this->private, offsetof(private_key_t, destroy));
pthread_rwlock_destroy(&this->lock);
this->lock->destroy(this->lock);
free(this);
}
@@ -974,7 +973,7 @@ stroke_cred_t *stroke_cred_create()
this->certs = linked_list_create();
this->shared = linked_list_create();
this->private = linked_list_create();
pthread_rwlock_init(&this->lock, NULL);
this->lock = rwlock_create(RWLOCK_DEFAULT);
load_certs(this);
load_secrets(this);