diff options
author | dimitri staessens <dimitri.staessens@ugent.be> | 2017-03-31 09:58:23 +0000 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2017-03-31 09:58:23 +0000 |
commit | ad01a7fd0b6cd798b2d5a2901ae8499b25360707 (patch) | |
tree | 16b6fd66c3fe93d178e10a137179923b513851f9 /src/irmd/irm_flow.c | |
parent | 5f79a21b80e68ba59616f0fa431287c3e94c43cf (diff) | |
parent | 7ba0fd0ce19244745c8d2512ce8a003783d914a7 (diff) | |
download | ouroboros-ad01a7fd0b6cd798b2d5a2901ae8499b25360707.tar.gz ouroboros-ad01a7fd0b6cd798b2d5a2901ae8499b25360707.zip |
Merged in dstaesse/ouroboros/be-new-api (pull request #439)
lib: Revise flow allocation API
Diffstat (limited to 'src/irmd/irm_flow.c')
-rw-r--r-- | src/irmd/irm_flow.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/irmd/irm_flow.c b/src/irmd/irm_flow.c index 99966561..4e7c22ef 100644 --- a/src/irmd/irm_flow.c +++ b/src/irmd/irm_flow.c @@ -45,6 +45,7 @@ struct irm_flow * irm_flow_create(pid_t n_api, } if (pthread_mutex_init(&f->state_lock, NULL)) { + pthread_cond_destroy(&f->state_cond); free(f); return NULL; } @@ -63,6 +64,9 @@ struct irm_flow * irm_flow_create(pid_t n_api, f->n_1_rb = shm_rbuff_create(n_1_api, port_id); if (f->n_1_rb == NULL) { log_err("Could not create ringbuffer for AP-I %d.", n_1_api); + shm_rbuff_destroy(f->n_rb); + pthread_mutex_destroy(&f->state_lock); + pthread_cond_destroy(&f->state_cond); free(f); return NULL; } @@ -122,7 +126,8 @@ enum flow_state irm_flow_get_state(struct irm_flow * f) return state; } -void irm_flow_set_state(struct irm_flow * f, enum flow_state state) +void irm_flow_set_state(struct irm_flow * f, + enum flow_state state) { assert(f); assert(state != FLOW_DESTROY); @@ -135,7 +140,8 @@ void irm_flow_set_state(struct irm_flow * f, enum flow_state state) pthread_mutex_unlock(&f->state_lock); } -enum flow_state irm_flow_wait_state(struct irm_flow * f, enum flow_state state) +enum flow_state irm_flow_wait_state(struct irm_flow * f, + enum flow_state state) { assert(f); assert(state != FLOW_NULL); @@ -143,6 +149,8 @@ enum flow_state irm_flow_wait_state(struct irm_flow * f, enum flow_state state) pthread_mutex_lock(&f->state_lock); + assert(f->state != FLOW_NULL); + while (!(f->state == state || f->state == FLOW_DESTROY)) pthread_cond_wait(&f->state_cond, &f->state_lock); |