From 16a28c7d5a9c6772c087554869bbfc6be47d3eee Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 16 Nov 2016 18:52:18 +0100 Subject: irmd: Refactor irm_flow Creation and destruction of the rbuffs is now completely handled in the irm_flow. --- src/irmd/irm_flow.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'src/irmd/irm_flow.c') 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 +#include #include "irm_flow.h" @@ -28,20 +31,12 @@ #include #include -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; } -- cgit v1.2.3