summaryrefslogtreecommitdiff
path: root/src/irmd/registry.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/irmd/registry.c')
-rw-r--r--src/irmd/registry.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/src/irmd/registry.c b/src/irmd/registry.c
index c7e7b52d..f863af6a 100644
--- a/src/irmd/registry.c
+++ b/src/irmd/registry.c
@@ -92,30 +92,13 @@ static int reg_entry_init(struct reg_entry * e,
return 0;
}
-static void reg_entry_destroy(struct reg_entry * e)
+static void cancel_reg_entry_destroy(void * o)
{
- struct list_head * p = NULL;
- struct list_head * h = NULL;
-
- if (e == NULL)
- return;
-
- pthread_mutex_lock(&e->state_lock);
-
- if (e->state == REG_NAME_DESTROY) {
- pthread_mutex_unlock(&e->state_lock);
- return;
- }
-
- if (e->state != REG_NAME_FLOW_ACCEPT)
- e->state = REG_NAME_NULL;
- else
- e->state = REG_NAME_DESTROY;
-
- pthread_cond_broadcast(&e->state_cond);
+ struct reg_entry * e;
+ struct list_head * p;
+ struct list_head * h;
- while (e->state != REG_NAME_NULL)
- pthread_cond_wait(&e->state_cond, &e->state_lock);
+ e = (struct reg_entry *) o;
pthread_mutex_unlock(&e->state_lock);
@@ -148,6 +131,33 @@ static void reg_entry_destroy(struct reg_entry * e)
free(e);
}
+static void reg_entry_destroy(struct reg_entry * e)
+{
+ if (e == NULL)
+ return;
+
+ pthread_mutex_lock(&e->state_lock);
+
+ if (e->state == REG_NAME_DESTROY) {
+ pthread_mutex_unlock(&e->state_lock);
+ return;
+ }
+
+ if (e->state != REG_NAME_FLOW_ACCEPT)
+ e->state = REG_NAME_NULL;
+ else
+ e->state = REG_NAME_DESTROY;
+
+ pthread_cond_broadcast(&e->state_cond);
+
+ pthread_cleanup_push(cancel_reg_entry_destroy, e);
+
+ while (e->state != REG_NAME_NULL)
+ pthread_cond_wait(&e->state_cond, &e->state_lock);
+
+ pthread_cleanup_pop(true);
+}
+
static bool reg_entry_is_local_in_dif(struct reg_entry * e,
const char * dif_name)
{
@@ -459,6 +469,9 @@ int reg_entry_leave_state(struct reg_entry * e,
pthread_mutex_lock(&e->state_lock);
+ pthread_cleanup_push((void *)(void *) pthread_mutex_unlock,
+ &e->state_lock);
+
while (e->state == state && ret != -ETIMEDOUT)
if (timeout)
ret = -pthread_cond_timedwait(&e->state_cond,
@@ -474,7 +487,7 @@ int reg_entry_leave_state(struct reg_entry * e,
pthread_cond_broadcast(&e->state_cond);
}
- pthread_mutex_unlock(&e->state_lock);
+ pthread_cleanup_pop(true);
return ret;
}