summaryrefslogtreecommitdiff
path: root/src/irmd/registry.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-07-27 18:57:44 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-07-27 18:57:44 +0200
commit7c18c1c74ac4771ffe9b0533b5bdd447c29e9802 (patch)
tree0229b141341e9c64c91e850469ae31d819f0fdba /src/irmd/registry.c
parent6c54691d1931118155360ac010671ff554cd4f71 (diff)
downloadouroboros-7c18c1c74ac4771ffe9b0533b5bdd447c29e9802.tar.gz
ouroboros-7c18c1c74ac4771ffe9b0533b5bdd447c29e9802.zip
irmd: Fix shutdown
When a pending accept is shutdown on irmd exit, there are no more threads running, but it should also change the state to NULL. This is now correctly handled in the cleanup of the cancellation point. Also fixed a busy wait with a condition variable.
Diffstat (limited to 'src/irmd/registry.c')
-rw-r--r--src/irmd/registry.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/irmd/registry.c b/src/irmd/registry.c
index ab47fede..a1d1238d 100644
--- a/src/irmd/registry.c
+++ b/src/irmd/registry.c
@@ -114,6 +114,13 @@ static void reg_api_destroy(struct reg_api * i)
free(i);
}
+static void cleanup_sleeper(void * o) {
+ struct reg_api * i = (struct reg_api *) o;
+ i->state = REG_I_NULL;
+ pthread_cond_signal(&i->state_cond);
+ pthread_mutex_unlock(&i->state_lock);
+}
+
void reg_api_sleep(struct reg_api * i)
{
if (i == NULL)
@@ -127,15 +134,11 @@ void reg_api_sleep(struct reg_api * i)
i->state = REG_I_SLEEP;
- pthread_cleanup_push((void(*)(void *)) pthread_mutex_unlock,
- (void *) &i->state_lock);
+ pthread_cleanup_push(cleanup_sleeper, (void *) i);
while (i->state == REG_I_SLEEP)
pthread_cond_wait(&i->state_cond, &i->state_lock);
- i->state = REG_I_NULL;
- pthread_cond_signal(&i->state_cond);
-
pthread_cleanup_pop(true);
}
@@ -235,8 +238,6 @@ static void reg_entry_destroy(struct reg_entry * e)
struct list_head * pos = NULL;
struct list_head * n = NULL;
- bool wait = true;
-
if (e == NULL)
return;
@@ -247,12 +248,6 @@ static void reg_entry_destroy(struct reg_entry * e)
pthread_cond_broadcast(&e->state_cond);
pthread_mutex_unlock(&e->state_lock);
- while (wait) {
- pthread_mutex_lock(&e->state_lock);
- pthread_cond_broadcast(&e->state_cond);
- pthread_mutex_unlock(&e->state_lock);
- }
-
pthread_mutex_destroy(&e->state_lock);
if (e->name != NULL)