diff options
-rw-r--r-- | src/ipcpd/normal/pol/flat.c | 16 | ||||
-rw-r--r-- | src/lib/dev.c | 14 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/ipcpd/normal/pol/flat.c b/src/ipcpd/normal/pol/flat.c index 0ab1e604..82c7db93 100644 --- a/src/ipcpd/normal/pol/flat.c +++ b/src/ipcpd/normal/pol/flat.c @@ -133,9 +133,12 @@ int flat_init(void) { struct ro_attr rattr; pthread_condattr_t cattr; + struct timespec t; char * name; - srand(time(NULL)); + clock_gettime(CLOCK_REALTIME, &t); + + srand(t.tv_nsec); flat.addr_in_use = false; ro_attr_init(&rattr); @@ -235,12 +238,22 @@ uint64_t flat_address(void) } pthread_mutex_lock(&flat.lock); + + if (ro_exists(ro_name)) { + pthread_mutex_unlock(&flat.lock); + free(ro_name); + free(buf); + continue; + } + + if (ro_create(ro_name, &attr, buf, sizeof(*msg))) { pthread_mutex_unlock(&flat.lock); free(ro_name); free(buf); return INVALID_ADDR; } + free(ro_name); while (flat.addr_in_use == false) { @@ -250,6 +263,7 @@ uint64_t flat_address(void) if (ret == -ETIMEDOUT) break; } + pthread_mutex_unlock(&flat.lock); } diff --git a/src/lib/dev.c b/src/lib/dev.c index b35045f5..8eb98506 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -101,7 +101,7 @@ static void port_set_state(struct port * p, enum port_state state) pthread_mutex_unlock(&p->state_lock); } -enum port_state port_wait_assign(struct port * p) +static enum port_state port_wait_assign(struct port * p) { enum port_state state; @@ -112,7 +112,7 @@ enum port_state port_wait_assign(struct port * p) return -1; } - while (!(p->state == PORT_ID_ASSIGNED || p->state == PORT_DESTROY)) + while (p->state == PORT_ID_PENDING) pthread_cond_wait(&p->state_cond, &p->state_lock); if (p->state == PORT_DESTROY) { @@ -214,6 +214,7 @@ static void reset_flow(int fd) ai.flows[fd].oflags = 0; ai.flows[fd].api = -1; ai.flows[fd].timesout = false; + ai.flows[fd].qos = QOS_CUBE_BE; } int ap_init(char * ap_name) @@ -268,6 +269,7 @@ int ap_init(char * ap_name) ai.flows[i].oflags = 0; ai.flows[i].api = -1; ai.flows[i].timesout = false; + ai.flows[i].qos = QOS_CUBE_BE; } ai.ports = malloc(sizeof(*ai.ports) * IRMD_MAX_FLOWS); @@ -311,16 +313,17 @@ void ap_fini() pthread_rwlock_rdlock(&ai.flows_lock); for (i = 0; i < AP_MAX_FLOWS; ++i) { - if (ai.flows[i].rx_rb != NULL) { + if (ai.flows[i].port_id != -1) { ssize_t idx; while ((idx = shm_rbuff_read(ai.flows[i].rx_rb)) >= 0) shm_rdrbuff_remove(ai.rdrb, idx); + port_set_state(&ai.ports[ai.flows[i].port_id], + PORT_NULL); + reset_flow(i); } - reset_flow(i); } for (i = 0; i < IRMD_MAX_FLOWS; ++i) { - ai.ports[i].state = PORT_NULL; pthread_mutex_destroy(&ai.ports[i].state_lock); pthread_cond_destroy(&ai.ports[i].state_cond); } @@ -1285,7 +1288,6 @@ int ipcp_flow_req_arr(pid_t api, char * dst_name, char * src_ae_name) if (ai.flows[fd].tx_rb == NULL) { irm_msg__free_unpacked(recv_msg, NULL); reset_flow(fd); - port_destroy(&ai.ports[port_id]); pthread_rwlock_unlock(&ai.flows_lock); pthread_rwlock_unlock(&ai.data_lock); return -1; |