diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-11-16 18:52:18 +0100 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-11-16 18:52:18 +0100 |
commit | 16a28c7d5a9c6772c087554869bbfc6be47d3eee (patch) | |
tree | c81dcfac4668a9e7ef759cae6a39526ce812b1be /src/irmd/irm_flow.c | |
parent | f7b9a391334130685dca1a85ab5fd3c5407991bf (diff) | |
download | ouroboros-16a28c7d5a9c6772c087554869bbfc6be47d3eee.tar.gz ouroboros-16a28c7d5a9c6772c087554869bbfc6be47d3eee.zip |
irmd: Refactor irm_flow
Creation and destruction of the rbuffs is now completely handled in
the irm_flow.
Diffstat (limited to 'src/irmd/irm_flow.c')
-rw-r--r-- | src/irmd/irm_flow.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/irmd/irm_flow.c b/src/irmd/irm_flow.c index a228db06..2456f1e2 100644 --- a/src/irmd/irm_flow.c +++ b/src/irmd/irm_flow.c @@ -20,7 +20,10 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define OUROBOROS_PREFIX "irm_flow" + #include <ouroboros/config.h> +#include <ouroboros/logs.h> #include "irm_flow.h" @@ -28,20 +31,12 @@ #include <stdbool.h> #include <assert.h> -struct irm_flow * irm_flow_create() +struct irm_flow * irm_flow_create(pid_t n_api, pid_t n_1_api, int port_id) { struct irm_flow * f = malloc(sizeof(*f)); if (f == NULL) return NULL; - f->n_api = -1; - f->n_1_api = -1; - f->port_id = -1; - f->n_rb = NULL; - f->n_1_rb = NULL; - - f->state = FLOW_NULL; - if (pthread_cond_init(&f->state_cond, NULL)) { free(f); return NULL; @@ -52,8 +47,29 @@ struct irm_flow * irm_flow_create() return NULL; } - f->t0.tv_sec = 0; - f->t0.tv_nsec = 0; + + f->n_api = n_api; + f->n_1_api = n_1_api; + f->port_id = port_id; + + f->n_rb = shm_rbuff_create(n_api, port_id); + if (f->n_rb == NULL) { + LOG_ERR("Could not create ringbuffer for AP-I %d.", n_api); + free(f); + return NULL; + } + + 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); + free(f); + return NULL; + } + + f->state = FLOW_ALLOC_PENDING; + + if (clock_gettime(CLOCK_MONOTONIC, &f->t0) < 0) + LOG_WARN("Failed to set timestamp."); return f; } |