summaryrefslogtreecommitdiff
path: root/src/irmd/main.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2016-07-27 18:57:44 +0200
committerdimitri staessens <[email protected]>2016-07-27 18:57:44 +0200
commit7c18c1c74ac4771ffe9b0533b5bdd447c29e9802 (patch)
tree0229b141341e9c64c91e850469ae31d819f0fdba /src/irmd/main.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/main.c')
-rw-r--r--src/irmd/main.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 6cf16505..d7119bac 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -1083,7 +1083,6 @@ static struct irm_flow * flow_req_arr(pid_t api,
struct reg_entry * rne = NULL;
struct irm_flow * pme = NULL;
- bool acc_wait = true;
enum reg_name_state state;
struct spawned_api * c_api;
@@ -1163,6 +1162,7 @@ static struct irm_flow * flow_req_arr(pid_t api,
pthread_rwlock_rdlock(&irmd->reg_lock);
pthread_mutex_lock(&rne->state_lock);
if (rne->state == REG_NAME_DESTROY) {
+ rne->state = REG_NAME_NULL;
pthread_mutex_unlock(&rne->state_lock);
pthread_rwlock_unlock(&irmd->reg_lock);
return NULL;
@@ -1207,14 +1207,14 @@ static struct irm_flow * flow_req_arr(pid_t api,
pthread_rwlock_unlock(&irmd->state_lock);
- while (acc_wait) {
- pthread_rwlock_rdlock(&irmd->state_lock);
- pthread_mutex_lock(&rne->state_lock);
- acc_wait = (rne->state == REG_NAME_FLOW_ARRIVED &&
- irmd->state == IRMD_RUNNING);
- pthread_mutex_unlock(&rne->state_lock);
- pthread_rwlock_unlock(&irmd->state_lock);
- }
+ pthread_cleanup_push((void(*)(void *)) pthread_mutex_unlock,
+ (void *) &rne->state_lock);
+
+ while (rne->state == REG_NAME_FLOW_ARRIVED &&
+ irmd->state == IRMD_RUNNING)
+ pthread_cond_wait(&rne->state_cond, &rne->state_lock);
+
+ pthread_cleanup_pop(true);
return pme;
}