linked_list_t *backends;
/**
- * locking mutex
+ * rwlock for backends
*/
- mutex_t *mutex;
+ rwlock_t *lock;
};
/**
*/
static void ike_enum_destroy(ike_data_t *data)
{
- data->this->mutex->unlock(data->this->mutex);
+ data->this->lock->unlock(data->this->lock);
free(data);
}
*/
static void peer_enum_destroy(peer_data_t *data)
{
- data->this->mutex->unlock(data->this->mutex);
+ data->this->lock->unlock(data->this->lock);
free(data);
}
DBG2(DBG_CFG, "looking for an ike config for %H...%H", me, other);
- this->mutex->lock(this->mutex);
+ this->lock->read_lock(this->lock);
enumerator = enumerator_create_nested(
this->backends->create_enumerator(this->backends),
(void*)ike_enum_create, data, (void*)ike_enum_destroy);
}
}
enumerator->destroy(enumerator);
- this->mutex->unlock(this->mutex);
+ this->lock->unlock(this->lock);
if (found)
{
DBG2(DBG_CFG, "found matching ike config: %s...%s with prio %d",
static enumerator_t *create_peer_cfg_enumerator(private_backend_manager_t *this)
{
- this->mutex->lock(this->mutex);
+ this->lock->read_lock(this->lock);
return enumerator_create_nested(
this->backends->create_enumerator(this->backends),
- (void*)peer_enum_create_all, this->mutex,
- (void*)this->mutex->unlock);
+ (void*)peer_enum_create_all, this->lock,
+ (void*)this->lock->unlock);
}
/**
data->me = my_id;
data->other = other_id;
- this->mutex->lock(this->mutex);
+ this->lock->read_lock(this->lock);
enumerator = enumerator_create_nested(
this->backends->create_enumerator(this->backends),
(void*)peer_enum_create, data, (void*)peer_enum_destroy);
found->get_other_id(found), best_peer, best_ike);
}
enumerator->destroy(enumerator);
- this->mutex->unlock(this->mutex);
+ this->lock->unlock(this->lock);
return found;
}
peer_cfg_t *config = NULL;
enumerator_t *enumerator;
- this->mutex->lock(this->mutex);
+ this->lock->read_lock(this->lock);
enumerator = this->backends->create_enumerator(this->backends);
while (config == NULL && enumerator->enumerate(enumerator, (void**)&backend))
{
config = backend->get_peer_cfg_by_name(backend, name);
}
enumerator->destroy(enumerator);
- this->mutex->unlock(this->mutex);
+ this->lock->unlock(this->lock);
return config;
}
*/
static void remove_backend(private_backend_manager_t *this, backend_t *backend)
{
- this->mutex->lock(this->mutex);
+ this->lock->write_lock(this->lock);
this->backends->remove(this->backends, backend, NULL);
- this->mutex->unlock(this->mutex);
+ this->lock->unlock(this->lock);
}
/**
*/
static void add_backend(private_backend_manager_t *this, backend_t *backend)
{
- this->mutex->lock(this->mutex);
+ this->lock->write_lock(this->lock);
this->backends->insert_last(this->backends, backend);
- this->mutex->unlock(this->mutex);
+ this->lock->unlock(this->lock);
}
/**
static void destroy(private_backend_manager_t *this)
{
this->backends->destroy(this->backends);
- this->mutex->destroy(this->mutex);
+ this->lock->destroy(this->lock);
free(this);
}
this->public.destroy = (void (*)(backend_manager_t*))destroy;
this->backends = linked_list_create();
- this->mutex = mutex_create(MUTEX_RECURSIVE);
+ this->lock = rwlock_create(RWLOCK_DEFAULT);
return &this->public;
}