summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-07-28 11:54:26 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-07-28 11:54:26 +0200
commite31d8dc166365cb501e86e832293b550bb277385 (patch)
tree251def449799fd5cce0f2c02883bcdab2a5dff7e /src/irmd
parent0bce1fb10d7dbed4beebcdb8a083c5019be5907e (diff)
parent67de2ae5f7aee25c077096bd90a8d4cd3cdcf094 (diff)
downloadouroboros-e31d8dc166365cb501e86e832293b550bb277385.tar.gz
ouroboros-e31d8dc166365cb501e86e832293b550bb277385.zip
Merge remote-tracking branch 'upstream/be' into be-enrolment
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/main.c34
-rw-r--r--src/irmd/registry.c21
2 files changed, 23 insertions, 32 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 6cf16505..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)
@@ -1083,7 +1079,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 +1158,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 +1203,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;
}
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)