/*
- * Copyright (C) 2011-2012 Tobias Brunner
+ * Copyright (C) 2011-2013 Tobias Brunner
* Copyright (C) 2009 Martin Willi
* Hochschule fuer Technik Rapperswil
*
#include <hydra.h>
#include <daemon.h>
#include <threading/rwlock.h>
+#include <threading/thread_value.h>
#include <collections/linked_list.h>
rwlock_t *lock;
/**
+ * track if the current thread is installing a trap policy
+ */
+ thread_value_t *installing;
+
+ /**
* listener to track acquiring IKE_SAs
*/
trap_listener_t listener;
}
this->lock->write_lock(this->lock);
+ this->installing->set(this->installing, this);
enumerator = this->traps->create_enumerator(this->traps);
while (enumerator->enumerate(enumerator, &entry))
{
}
}
enumerator->destroy(enumerator);
- this->lock->unlock(this->lock);
if (found)
{ /* config might have changed so update everything */
.child_sa = child_sa,
.peer_cfg = peer->get_ref(peer),
);
- this->lock->write_lock(this->lock);
this->traps->insert_last(this->traps, entry);
- this->lock->unlock(this->lock);
reqid = child_sa->get_reqid(child_sa);
}
+ this->installing->set(this->installing, NULL);
+ this->lock->unlock(this->lock);
if (status != SUCCESS)
{
entry_t *entry;
u_int32_t reqid = 0;
+ if (this->installing->get(this->installing))
+ { /* current thread holds the lock */
+ return reqid;
+ }
this->lock->read_lock(this->lock);
enumerator = this->traps->create_enumerator(this->traps);
while (enumerator->enumerate(enumerator, &entry))
{
charon->bus->remove_listener(charon->bus, &this->listener.listener);
this->traps->destroy_function(this->traps, (void*)destroy_entry);
+ this->installing->destroy(this->installing);
this->lock->destroy(this->lock);
free(this);
}
},
.traps = linked_list_create(),
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
+ .installing = thread_value_create(NULL),
);
charon->bus->add_listener(charon->bus, &this->listener.listener);