From 7c18c1c74ac4771ffe9b0533b5bdd447c29e9802 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 27 Jul 2016 18:57:44 +0200 Subject: 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. --- src/irmd/main.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/irmd/main.c') 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; } -- cgit v1.2.3 From f2e87e236ad89b4a3fc4dda59ed42ab9af04d08c Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 28 Jul 2016 11:46:55 +0200 Subject: irmd: Fix allocation result It was missing the FLOW_PENDING state. All states that are not FLOW_ALLOCATED should return -1. This is now fixed. --- src/irmd/main.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/irmd/main.c') diff --git a/src/irmd/main.c b/src/irmd/main.c index d7119bac..b071ff1c 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -998,17 +998,13 @@ static int flow_alloc_res(int port_id) return 0; } - if (e->state == FLOW_DESTROY) { - /* don't release the port_id, AP has to call dealloc */ - e->state = FLOW_NULL; - pthread_cond_signal(&e->state_cond); - pthread_mutex_unlock(&e->state_lock); - pthread_rwlock_unlock(&irmd->flows_lock); - pthread_rwlock_unlock(&irmd->state_lock); - return -1; - } + e->state = FLOW_NULL; + pthread_cond_signal(&e->state_cond); + pthread_mutex_unlock(&e->state_lock); + pthread_rwlock_unlock(&irmd->flows_lock); + pthread_rwlock_unlock(&irmd->state_lock); - return 0; + return -1; } static int flow_dealloc(int port_id) -- cgit v1.2.3