replaced most pthread_mutex/cond_t by wrapped mutex/condvar_t variant
This commit is contained in:
@@ -17,9 +17,8 @@
|
||||
|
||||
#include "eap_manager.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <utils/linked_list.h>
|
||||
#include <utils/mutex.h>
|
||||
|
||||
typedef struct private_eap_manager_t private_eap_manager_t;
|
||||
typedef struct eap_entry_t eap_entry_t;
|
||||
@@ -68,7 +67,7 @@ struct private_eap_manager_t {
|
||||
/**
|
||||
* mutex to lock methods
|
||||
*/
|
||||
pthread_mutex_t mutex;
|
||||
mutex_t *mutex;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -85,9 +84,9 @@ static void add_method(private_eap_manager_t *this, eap_type_t type,
|
||||
entry->role = role;
|
||||
entry->constructor = constructor;
|
||||
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
this->mutex->lock(this->mutex);
|
||||
this->methods->insert_last(this->methods, entry);
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +97,7 @@ static void remove_method(private_eap_manager_t *this, eap_constructor_t constru
|
||||
enumerator_t *enumerator;
|
||||
eap_entry_t *entry;
|
||||
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
this->mutex->lock(this->mutex);
|
||||
enumerator = this->methods->create_enumerator(this->methods);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
{
|
||||
@@ -109,7 +108,7 @@ static void remove_method(private_eap_manager_t *this, eap_constructor_t constru
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +123,7 @@ static eap_method_t* create_instance(private_eap_manager_t *this,
|
||||
eap_entry_t *entry;
|
||||
eap_method_t *method = NULL;
|
||||
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
this->mutex->lock(this->mutex);
|
||||
enumerator = this->methods->create_enumerator(this->methods);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
{
|
||||
@@ -139,7 +138,7 @@ static eap_method_t* create_instance(private_eap_manager_t *this,
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
this->mutex->unlock(this->mutex);
|
||||
return method;
|
||||
}
|
||||
|
||||
@@ -149,6 +148,7 @@ static eap_method_t* create_instance(private_eap_manager_t *this,
|
||||
static void destroy(private_eap_manager_t *this)
|
||||
{
|
||||
this->methods->destroy_function(this->methods, free);
|
||||
this->mutex->destroy(this->mutex);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ eap_manager_t *eap_manager_create()
|
||||
this->public.destroy = (void(*)(eap_manager_t*))destroy;
|
||||
|
||||
this->methods = linked_list_create();
|
||||
pthread_mutex_init(&this->mutex, NULL);
|
||||
this->mutex = mutex_create(MUTEX_DEFAULT);
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
|
||||
#include "connect_manager.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <daemon.h>
|
||||
#include <utils/mutex.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <crypto/hashers/hasher.h>
|
||||
|
||||
@@ -59,7 +59,7 @@ struct private_connect_manager_t {
|
||||
/**
|
||||
* Lock for exclusivly accessing the manager.
|
||||
*/
|
||||
pthread_mutex_t mutex;
|
||||
mutex_t *mutex;
|
||||
|
||||
/**
|
||||
* Hasher to generate signatures
|
||||
@@ -845,20 +845,20 @@ static job_requeue_t initiator_finish(callback_data_t *data)
|
||||
{
|
||||
private_connect_manager_t *this = data->connect_manager;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
check_list_t *checklist;
|
||||
if (get_checklist_by_id(this, data->connect_id, &checklist) != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "checklist with id '%#B' not found, can't finish connectivity checks",
|
||||
&data->connect_id);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return JOB_REQUEUE_NONE;
|
||||
}
|
||||
|
||||
finish_checks(this, checklist);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
return JOB_REQUEUE_NONE;
|
||||
}
|
||||
@@ -929,14 +929,14 @@ static job_requeue_t retransmit(callback_data_t *data)
|
||||
{
|
||||
private_connect_manager_t *this = data->connect_manager;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
check_list_t *checklist;
|
||||
if (get_checklist_by_id(this, data->connect_id, &checklist) != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "checklist with id '%#B' not found, can't retransmit connectivity check",
|
||||
&data->connect_id);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return JOB_REQUEUE_NONE;
|
||||
}
|
||||
|
||||
@@ -980,7 +980,7 @@ retransmit_end:
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
/* we reschedule it manually */
|
||||
return JOB_REQUEUE_NONE;
|
||||
@@ -1078,14 +1078,14 @@ static job_requeue_t sender(callback_data_t *data)
|
||||
{
|
||||
private_connect_manager_t *this = data->connect_manager;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
check_list_t *checklist;
|
||||
if (get_checklist_by_id(this, data->connect_id, &checklist) != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "checklist with id '%#B' not found, can't send connectivity check",
|
||||
&data->connect_id);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return JOB_REQUEUE_NONE;
|
||||
}
|
||||
|
||||
@@ -1100,7 +1100,7 @@ static job_requeue_t sender(callback_data_t *data)
|
||||
if (checklist->pairs->find_first(checklist->pairs,
|
||||
(linked_list_match_t)match_waiting_pair, (void**)&pair) != SUCCESS)
|
||||
{
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
DBG1(DBG_IKE, "no pairs in waiting state, aborting");
|
||||
return JOB_REQUEUE_NONE;
|
||||
}
|
||||
@@ -1126,7 +1126,7 @@ static job_requeue_t sender(callback_data_t *data)
|
||||
/* schedule this job again */
|
||||
schedule_checks(this, checklist, ME_INTERVAL);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
/* we reschedule it manually */
|
||||
return JOB_REQUEUE_NONE;
|
||||
@@ -1345,7 +1345,7 @@ static void process_check(private_connect_manager_t *this, message_t *message)
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
check_list_t *checklist;
|
||||
if (get_checklist_by_id(this, check->connect_id, &checklist) != SUCCESS)
|
||||
@@ -1353,7 +1353,7 @@ static void process_check(private_connect_manager_t *this, message_t *message)
|
||||
DBG1(DBG_IKE, "checklist with id '%#B' not found",
|
||||
&check->connect_id);
|
||||
check_destroy(check);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1363,7 +1363,7 @@ static void process_check(private_connect_manager_t *this, message_t *message)
|
||||
DBG1(DBG_IKE, "connectivity check verification failed");
|
||||
check_destroy(check);
|
||||
chunk_free(&sig);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return;
|
||||
}
|
||||
chunk_free(&sig);
|
||||
@@ -1377,7 +1377,7 @@ static void process_check(private_connect_manager_t *this, message_t *message)
|
||||
process_response(this, check, checklist);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
check_destroy(check);
|
||||
}
|
||||
@@ -1392,7 +1392,7 @@ static bool check_and_register(private_connect_manager_t *this,
|
||||
initiated_t *initiated;
|
||||
bool already_there = TRUE;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
if (get_initiated_by_ids(this, id, peer_id, &initiated) != SUCCESS)
|
||||
{
|
||||
@@ -1408,7 +1408,7 @@ static bool check_and_register(private_connect_manager_t *this,
|
||||
initiated->mediated->insert_last(initiated->mediated, mediated_sa->clone(mediated_sa));
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
return already_there;
|
||||
}
|
||||
@@ -1421,12 +1421,12 @@ static void check_and_initiate(private_connect_manager_t *this, ike_sa_id_t *med
|
||||
{
|
||||
initiated_t *initiated;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
if (get_initiated_by_ids(this, id, peer_id, &initiated) != SUCCESS)
|
||||
{
|
||||
DBG2(DBG_IKE, "no waiting mediated connections with '%D'", peer_id);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1439,7 +1439,7 @@ static void check_and_initiate(private_connect_manager_t *this, ike_sa_id_t *med
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1451,20 +1451,20 @@ static status_t set_initiator_data(private_connect_manager_t *this,
|
||||
{
|
||||
check_list_t *checklist;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
if (get_checklist_by_id(this, connect_id, NULL) == SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "checklist with id '%#B' already exists, aborting",
|
||||
&connect_id);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
checklist = check_list_create(initiator, responder, connect_id, key, endpoints, is_initiator);
|
||||
this->checklists->insert_last(this->checklists, checklist);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -1477,13 +1477,13 @@ static status_t set_responder_data(private_connect_manager_t *this,
|
||||
{
|
||||
check_list_t *checklist;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
if (get_checklist_by_id(this, connect_id, &checklist) != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "checklist with id '%#B' not found",
|
||||
&connect_id);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -1496,7 +1496,7 @@ static status_t set_responder_data(private_connect_manager_t *this,
|
||||
/* send the first check immediately */
|
||||
schedule_checks(this, checklist, 0);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -1508,13 +1508,13 @@ static status_t stop_checks(private_connect_manager_t *this, chunk_t connect_id)
|
||||
{
|
||||
check_list_t *checklist;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
if (get_checklist_by_id(this, connect_id, &checklist) != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "checklist with id '%#B' not found",
|
||||
&connect_id);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -1523,7 +1523,7 @@ static status_t stop_checks(private_connect_manager_t *this, chunk_t connect_id)
|
||||
remove_checklist(this, checklist);
|
||||
check_list_destroy(checklist);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -1533,14 +1533,14 @@ static status_t stop_checks(private_connect_manager_t *this, chunk_t connect_id)
|
||||
*/
|
||||
static void destroy(private_connect_manager_t *this)
|
||||
{
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
this->hasher->destroy(this->hasher);
|
||||
this->checklists->destroy_function(this->checklists, (void*)check_list_destroy);
|
||||
this->initiated->destroy_function(this->initiated, (void*)initiated_destroy);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
pthread_mutex_destroy(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
this->mutex->destroy(this->mutex);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@@ -1570,7 +1570,7 @@ connect_manager_t *connect_manager_create()
|
||||
this->checklists = linked_list_create();
|
||||
this->initiated = linked_list_create();
|
||||
|
||||
pthread_mutex_init(&(this->mutex), NULL);
|
||||
this->mutex = mutex_create(MUTEX_DEFAULT);
|
||||
|
||||
return (connect_manager_t*)this;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ike_sa_manager.h"
|
||||
@@ -24,6 +23,7 @@
|
||||
#include <daemon.h>
|
||||
#include <sa/ike_sa_id.h>
|
||||
#include <bus/bus.h>
|
||||
#include <utils/mutex.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <crypto/hashers/hasher.h>
|
||||
|
||||
@@ -42,7 +42,7 @@ struct entry_t {
|
||||
/**
|
||||
* Condvar where threads can wait until ike_sa_t object is free for use again.
|
||||
*/
|
||||
pthread_cond_t condvar;
|
||||
condvar_t *condvar;
|
||||
|
||||
/**
|
||||
* Is this ike_sa currently checked out?
|
||||
@@ -107,6 +107,7 @@ static status_t entry_destroy(entry_t *this)
|
||||
DESTROY_IF(this->other);
|
||||
DESTROY_IF(this->my_id);
|
||||
DESTROY_IF(this->other_id);
|
||||
this->condvar->destroy(this->condvar);
|
||||
free(this);
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -119,7 +120,7 @@ static entry_t *entry_create(ike_sa_id_t *ike_sa_id)
|
||||
entry_t *this = malloc_thing(entry_t);
|
||||
|
||||
this->waiting_threads = 0;
|
||||
pthread_cond_init(&this->condvar, NULL);
|
||||
this->condvar = condvar_create(CONDVAR_DEFAULT);
|
||||
|
||||
/* we set checkout flag when we really give it out */
|
||||
this->checked_out = FALSE;
|
||||
@@ -155,7 +156,7 @@ struct private_ike_sa_manager_t {
|
||||
/**
|
||||
* Lock for exclusivly accessing the manager.
|
||||
*/
|
||||
pthread_mutex_t mutex;
|
||||
mutex_t *mutex;
|
||||
|
||||
/**
|
||||
* Linked list with entries for the ike_sa_t objects.
|
||||
@@ -278,9 +279,9 @@ static status_t delete_entry(private_ike_sa_manager_t *this, entry_t *entry)
|
||||
while (entry->waiting_threads)
|
||||
{
|
||||
/* wake up all */
|
||||
pthread_cond_broadcast(&(entry->condvar));
|
||||
entry->condvar->broadcast(entry->condvar);
|
||||
/* they will wake us again when their work is done */
|
||||
pthread_cond_wait(&(entry->condvar), &(this->mutex));
|
||||
entry->condvar->wait(entry->condvar, this->mutex);
|
||||
}
|
||||
|
||||
DBG2(DBG_MGR, "found entry by pointer, deleting it");
|
||||
@@ -310,14 +311,14 @@ static bool wait_for_entry(private_ike_sa_manager_t *this, entry_t *entry)
|
||||
/* so wait until we can get it for us.
|
||||
* we register us as waiting. */
|
||||
entry->waiting_threads++;
|
||||
pthread_cond_wait(&(entry->condvar), &(this->mutex));
|
||||
entry->condvar->wait(entry->condvar, this->mutex);
|
||||
entry->waiting_threads--;
|
||||
}
|
||||
/* hm, a deletion request forbids us to get this SA, get next one */
|
||||
if (entry->driveout_waiting_threads)
|
||||
{
|
||||
/* we must signal here, others may be waiting on it, too */
|
||||
pthread_cond_signal(&(entry->condvar));
|
||||
entry->condvar->signal(entry->condvar);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
@@ -345,7 +346,7 @@ static ike_sa_t* checkout(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id
|
||||
DBG2(DBG_MGR, "checkout IKE_SA, %d IKE_SAs in manager",
|
||||
this->ike_sa_list->get_count(this->ike_sa_list));
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
if (get_entry_by_id(this, ike_sa_id, &entry) == SUCCESS)
|
||||
{
|
||||
if (wait_for_entry(this, entry))
|
||||
@@ -355,7 +356,7 @@ static ike_sa_t* checkout(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id
|
||||
ike_sa = entry->ike_sa;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
this->mutex->unlock(this->mutex);
|
||||
charon->bus->set_sa(charon->bus, ike_sa);
|
||||
return ike_sa;
|
||||
}
|
||||
@@ -378,10 +379,10 @@ static ike_sa_t *checkout_new(private_ike_sa_manager_t* this, bool initiator)
|
||||
}
|
||||
entry = entry_create(id);
|
||||
id->destroy(id);
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
this->mutex->lock(this->mutex);
|
||||
this->ike_sa_list->insert_last(this->ike_sa_list, entry);
|
||||
entry->checked_out = TRUE;
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
this->mutex->unlock(this->mutex);
|
||||
DBG2(DBG_MGR, "created IKE_SA, %d IKE_SAs in manager",
|
||||
this->ike_sa_list->get_count(this->ike_sa_list));
|
||||
return entry->ike_sa;
|
||||
@@ -413,7 +414,7 @@ static ike_sa_t* checkout_by_message(private_ike_sa_manager_t* this,
|
||||
this->hasher->allocate_hash(this->hasher, data, &hash);
|
||||
chunk_free(&data);
|
||||
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
this->mutex->lock(this->mutex);
|
||||
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
{
|
||||
@@ -422,7 +423,7 @@ static ike_sa_t* checkout_by_message(private_ike_sa_manager_t* this,
|
||||
if (entry->message_id == 0)
|
||||
{
|
||||
enumerator->destroy(enumerator);
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
this->mutex->unlock(this->mutex);
|
||||
chunk_free(&hash);
|
||||
id->destroy(id);
|
||||
DBG1(DBG_MGR, "ignoring IKE_SA_INIT, already processing");
|
||||
@@ -439,7 +440,7 @@ static ike_sa_t* checkout_by_message(private_ike_sa_manager_t* this,
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
if (ike_sa == NULL)
|
||||
{
|
||||
@@ -450,11 +451,11 @@ static ike_sa_t* checkout_by_message(private_ike_sa_manager_t* this,
|
||||
id->set_responder_spi(id, get_next_spi(this));
|
||||
entry = entry_create(id);
|
||||
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
this->mutex->lock(this->mutex);
|
||||
this->ike_sa_list->insert_last(this->ike_sa_list, entry);
|
||||
entry->checked_out = TRUE;
|
||||
entry->message_id = message->get_message_id(message);
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
this->mutex->unlock(this->mutex);
|
||||
entry->init_hash = hash;
|
||||
ike_sa = entry->ike_sa;
|
||||
}
|
||||
@@ -473,7 +474,7 @@ static ike_sa_t* checkout_by_message(private_ike_sa_manager_t* this,
|
||||
return ike_sa;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
if (get_entry_by_id(this, id, &entry) == SUCCESS)
|
||||
{
|
||||
/* only check out if we are not processing this request */
|
||||
@@ -496,7 +497,7 @@ static ike_sa_t* checkout_by_message(private_ike_sa_manager_t* this,
|
||||
ike_sa = entry->ike_sa;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
this->mutex->unlock(this->mutex);
|
||||
id->destroy(id);
|
||||
charon->bus->set_sa(charon->bus, ike_sa);
|
||||
return ike_sa;
|
||||
@@ -521,7 +522,7 @@ static ike_sa_t* checkout_by_config(private_ike_sa_manager_t *this,
|
||||
my_host = host_create_from_dns(ike_cfg->get_my_addr(ike_cfg), 0, 0);
|
||||
other_host = host_create_from_dns(ike_cfg->get_other_addr(ike_cfg), 0, 0);
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
if (my_host && other_host && this->reuse_ikesa)
|
||||
{
|
||||
@@ -604,7 +605,7 @@ static ike_sa_t* checkout_by_config(private_ike_sa_manager_t *this,
|
||||
new_entry->checked_out = TRUE;
|
||||
ike_sa = new_entry->ike_sa;
|
||||
}
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
charon->bus->set_sa(charon->bus, ike_sa);
|
||||
return ike_sa;
|
||||
}
|
||||
@@ -621,7 +622,7 @@ static ike_sa_t* checkout_by_id(private_ike_sa_manager_t *this, u_int32_t id,
|
||||
ike_sa_t *ike_sa = NULL;
|
||||
child_sa_t *child_sa;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
@@ -658,7 +659,7 @@ static ike_sa_t* checkout_by_id(private_ike_sa_manager_t *this, u_int32_t id,
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
charon->bus->set_sa(charon->bus, ike_sa);
|
||||
return ike_sa;
|
||||
@@ -676,7 +677,7 @@ static ike_sa_t* checkout_by_name(private_ike_sa_manager_t *this, char *name,
|
||||
ike_sa_t *ike_sa = NULL;
|
||||
child_sa_t *child_sa;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
@@ -713,7 +714,7 @@ static ike_sa_t* checkout_by_name(private_ike_sa_manager_t *this, char *name,
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
charon->bus->set_sa(charon->bus, ike_sa);
|
||||
return ike_sa;
|
||||
@@ -733,7 +734,7 @@ static ike_sa_t* checkout_duplicate(private_ike_sa_manager_t *this,
|
||||
me = ike_sa->get_my_id(ike_sa);
|
||||
other = ike_sa->get_other_id(ike_sa);
|
||||
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
this->mutex->lock(this->mutex);
|
||||
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
{
|
||||
@@ -756,7 +757,7 @@ static ike_sa_t* checkout_duplicate(private_ike_sa_manager_t *this,
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
this->mutex->unlock(this->mutex);
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
@@ -765,7 +766,7 @@ static ike_sa_t* checkout_duplicate(private_ike_sa_manager_t *this,
|
||||
*/
|
||||
static void enumerator_unlock(private_ike_sa_manager_t *this)
|
||||
{
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -787,7 +788,7 @@ static bool enumerator_filter(private_ike_sa_manager_t *this,
|
||||
*/
|
||||
static enumerator_t *create_enumerator(private_ike_sa_manager_t* this)
|
||||
{
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
this->mutex->lock(this->mutex);
|
||||
return enumerator_create_filter(
|
||||
this->ike_sa_list->create_enumerator(this->ike_sa_list),
|
||||
(void*)enumerator_filter, this, (void*)enumerator_unlock);
|
||||
@@ -813,7 +814,7 @@ static status_t checkin(private_ike_sa_manager_t *this, ike_sa_t *ike_sa)
|
||||
|
||||
DBG2(DBG_MGR, "checkin IKE_SA");
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
/* look for the entry */
|
||||
if (get_entry_by_sa(this, ike_sa, &entry) == SUCCESS)
|
||||
@@ -846,7 +847,7 @@ static status_t checkin(private_ike_sa_manager_t *this, ike_sa_t *ike_sa)
|
||||
entry->other_id = other_id->clone(other_id);
|
||||
}
|
||||
DBG2(DBG_MGR, "check-in of IKE_SA successful.");
|
||||
pthread_cond_signal(&(entry->condvar));
|
||||
entry->condvar->signal(entry->condvar);
|
||||
retval = SUCCESS;
|
||||
}
|
||||
else
|
||||
@@ -858,7 +859,7 @@ static status_t checkin(private_ike_sa_manager_t *this, ike_sa_t *ike_sa)
|
||||
|
||||
DBG2(DBG_MGR, "%d IKE_SAs in manager now",
|
||||
this->ike_sa_list->get_count(this->ike_sa_list));
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
charon->bus->set_sa(charon->bus, NULL);
|
||||
return retval;
|
||||
@@ -882,7 +883,7 @@ static status_t checkin_and_destroy(private_ike_sa_manager_t *this, ike_sa_t *ik
|
||||
ike_sa_id = ike_sa->get_id(ike_sa);
|
||||
DBG2(DBG_MGR, "checkin and destroy IKE_SA");
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
if (get_entry_by_sa(this, ike_sa, &entry) == SUCCESS)
|
||||
{
|
||||
@@ -901,7 +902,7 @@ static status_t checkin_and_destroy(private_ike_sa_manager_t *this, ike_sa_t *ik
|
||||
}
|
||||
charon->bus->set_sa(charon->bus, NULL);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -914,7 +915,7 @@ static int get_half_open_count(private_ike_sa_manager_t *this, host_t *ip)
|
||||
entry_t *entry;
|
||||
int count = 0;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
{
|
||||
@@ -938,7 +939,7 @@ static int get_half_open_count(private_ike_sa_manager_t *this, host_t *ip)
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -951,7 +952,7 @@ static void flush(private_ike_sa_manager_t *this)
|
||||
enumerator_t *enumerator;
|
||||
entry_t *entry;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
DBG2(DBG_MGR, "going to destroy IKE_SA manager and all managed IKE_SA's");
|
||||
/* Step 1: drive out all waiting threads */
|
||||
DBG2(DBG_MGR, "set driveout flags for all stored IKE_SA's");
|
||||
@@ -971,9 +972,9 @@ static void flush(private_ike_sa_manager_t *this)
|
||||
while (entry->waiting_threads)
|
||||
{
|
||||
/* wake up all */
|
||||
pthread_cond_broadcast(&(entry->condvar));
|
||||
entry->condvar->broadcast(entry->condvar);
|
||||
/* go sleeping until they are gone */
|
||||
pthread_cond_wait(&(entry->condvar), &(this->mutex));
|
||||
entry->condvar->wait(entry->condvar, this->mutex);
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
@@ -996,7 +997,7 @@ static void flush(private_ike_sa_manager_t *this)
|
||||
entry_destroy(entry);
|
||||
}
|
||||
charon->bus->set_sa(charon->bus, NULL);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1007,7 +1008,7 @@ static void destroy(private_ike_sa_manager_t *this)
|
||||
this->ike_sa_list->destroy(this->ike_sa_list);
|
||||
this->rng->destroy(this->rng);
|
||||
this->hasher->destroy(this->hasher);
|
||||
|
||||
this->mutex->destroy(this->mutex);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@@ -1050,7 +1051,7 @@ ike_sa_manager_t *ike_sa_manager_create()
|
||||
return NULL;
|
||||
}
|
||||
this->ike_sa_list = linked_list_create();
|
||||
pthread_mutex_init(&this->mutex, NULL);
|
||||
this->mutex = mutex_create(MUTEX_DEFAULT);
|
||||
this->reuse_ikesa = lib->settings->get_bool(lib->settings,
|
||||
"charon.reuse_ikesa", TRUE);
|
||||
return &this->public;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
#include "mediation_manager.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <daemon.h>
|
||||
#include <utils/mutex.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <processing/jobs/mediation_job.h>
|
||||
|
||||
@@ -80,7 +80,7 @@ struct private_mediation_manager_t {
|
||||
/**
|
||||
* Lock for exclusivly accessing the manager.
|
||||
*/
|
||||
pthread_mutex_t mutex;
|
||||
mutex_t *mutex;
|
||||
|
||||
/**
|
||||
* Linked list with state entries.
|
||||
@@ -182,7 +182,7 @@ static void remove_sa(private_mediation_manager_t *this, ike_sa_id_t *ike_sa_id)
|
||||
iterator_t *iterator;
|
||||
peer_t *peer;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
iterator = this->peers->create_iterator(this->peers, TRUE);
|
||||
while (iterator->iterate(iterator, (void**)&peer))
|
||||
@@ -199,7 +199,7 @@ static void remove_sa(private_mediation_manager_t *this, ike_sa_id_t *ike_sa_id)
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,7 +211,7 @@ static void update_sa_id(private_mediation_manager_t *this, identification_t *pe
|
||||
peer_t *peer;
|
||||
bool found = FALSE;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
iterator = this->peers->create_iterator(this->peers, TRUE);
|
||||
while (iterator->iterate(iterator, (void**)&peer))
|
||||
@@ -244,7 +244,7 @@ static void update_sa_id(private_mediation_manager_t *this, identification_t *pe
|
||||
requester->destroy(requester);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,17 +256,17 @@ static ike_sa_id_t *check(private_mediation_manager_t *this,
|
||||
peer_t *peer;
|
||||
ike_sa_id_t *ike_sa_id;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
if (get_peer_by_id(this, peer_id, &peer) != SUCCESS)
|
||||
{
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ike_sa_id = peer->ike_sa_id;
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
return ike_sa_id;
|
||||
}
|
||||
@@ -280,7 +280,7 @@ static ike_sa_id_t *check_and_register(private_mediation_manager_t *this,
|
||||
peer_t *peer;
|
||||
ike_sa_id_t *ike_sa_id;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
if (get_peer_by_id(this, peer_id, &peer) != SUCCESS)
|
||||
{
|
||||
@@ -294,13 +294,13 @@ static ike_sa_id_t *check_and_register(private_mediation_manager_t *this,
|
||||
/* the peer is not online */
|
||||
DBG2(DBG_IKE, "requested peer '%D' is offline, registering peer '%D'", peer_id, requester);
|
||||
register_peer(peer, requester);
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ike_sa_id = peer->ike_sa_id;
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
return ike_sa_id;
|
||||
}
|
||||
@@ -310,12 +310,12 @@ static ike_sa_id_t *check_and_register(private_mediation_manager_t *this,
|
||||
*/
|
||||
static void destroy(private_mediation_manager_t *this)
|
||||
{
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
this->mutex->lock(this->mutex);
|
||||
|
||||
this->peers->destroy_function(this->peers, (void*)peer_destroy);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
pthread_mutex_destroy(&(this->mutex));
|
||||
this->mutex->unlock(this->mutex);
|
||||
this->mutex->destroy(this->mutex);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ mediation_manager_t *mediation_manager_create()
|
||||
this->public.check_and_register = (ike_sa_id_t*(*)(mediation_manager_t*,identification_t*,identification_t*))check_and_register;
|
||||
|
||||
this->peers = linked_list_create();
|
||||
pthread_mutex_init(&(this->mutex), NULL);
|
||||
this->mutex = mutex_create(MUTEX_DEFAULT);
|
||||
|
||||
return (mediation_manager_t*)this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user