diff options
author | Dimitri Staessens <[email protected]> | 2023-03-14 12:50:26 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2023-03-18 17:12:27 +0100 |
commit | 3b2f38aeafa1d6d2976dd5581ef46a5d3b463825 (patch) | |
tree | b6672c1baaa813fb5f8865675a322efa280ab532 | |
parent | ed90f46a8207cb1289704ea64bc490d5835f3010 (diff) | |
download | ouroboros-3b2f38aeafa1d6d2976dd5581ef46a5d3b463825.tar.gz ouroboros-3b2f38aeafa1d6d2976dd5581ef46a5d3b463825.zip |
irmd: Use deadline instead of timeout in mainloop
Reduces the places where we need to do this conversion for
pthread_cond_timedwait.
Signed-off-by: Dimitri Staessens <[email protected]>
Signed-off-by: Sander Vrijders <[email protected]>
-rw-r--r-- | src/irmd/irm_flow.c | 19 | ||||
-rw-r--r-- | src/irmd/main.c | 27 | ||||
-rw-r--r-- | src/irmd/proc_table.c | 12 |
3 files changed, 25 insertions, 33 deletions
diff --git a/src/irmd/irm_flow.c b/src/irmd/irm_flow.c index 8bdda86b..44d3fb7e 100644 --- a/src/irmd/irm_flow.c +++ b/src/irmd/irm_flow.c @@ -176,23 +176,16 @@ void irm_flow_set_state(struct irm_flow * f, int irm_flow_wait_state(struct irm_flow * f, enum flow_state state, - struct timespec * timeo) + struct timespec * dl) { int ret = 0; int s; - struct timespec dl; - assert(f); assert(state != FLOW_NULL); assert(state != FLOW_DESTROY); assert(state != FLOW_DEALLOC_PENDING); - if (timeo != NULL) { - clock_gettime(PTHREAD_COND_CLOCK, &dl); - ts_add(&dl, timeo, &dl); - } - pthread_mutex_lock(&f->state_lock); assert(f->state != FLOW_NULL); @@ -203,13 +196,13 @@ int irm_flow_wait_state(struct irm_flow * f, f->state == FLOW_DESTROY || f->state == FLOW_DEALLOC_PENDING) && ret != -ETIMEDOUT) { - if (timeo == NULL) - ret = -pthread_cond_wait(&f->state_cond, - &f->state_lock); - else + if (dl != NULL) ret = -pthread_cond_timedwait(&f->state_cond, &f->state_lock, - &dl); + dl); + else + ret = -pthread_cond_wait(&f->state_cond, + &f->state_lock); } if (f->state == FLOW_DESTROY || diff --git a/src/irmd/main.c b/src/irmd/main.c index 5ef9a82e..e8a73aa0 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1275,7 +1275,7 @@ static int proc_announce(pid_t pid, } static int flow_accept(pid_t pid, - struct timespec * timeo, + struct timespec * dl, struct irm_flow * f_out, const void * data, size_t len) @@ -1312,7 +1312,7 @@ static int flow_accept(pid_t pid, pthread_rwlock_unlock(&irmd.reg_lock); - ret = proc_entry_sleep(pe, timeo); + ret = proc_entry_sleep(pe, dl); if (ret == -ETIMEDOUT) return -ETIMEDOUT; @@ -1418,7 +1418,7 @@ static int flow_accept(pid_t pid, static int flow_join(pid_t pid, const char * dst, qosspec_t qs, - struct timespec * timeo, + struct timespec * dl, struct irm_flow * f_out) { struct irm_flow * f; @@ -1476,7 +1476,7 @@ static int flow_join(pid_t pid, free(hash); - state = irm_flow_wait_state(f, FLOW_ALLOCATED, timeo); + state = irm_flow_wait_state(f, FLOW_ALLOCATED, dl); if (state != FLOW_ALLOCATED) { if (state == -ETIMEDOUT) { log_dbg("Flow allocation timed out"); @@ -1510,7 +1510,7 @@ static int flow_join(pid_t pid, static int flow_alloc(pid_t pid, const char * dst, qosspec_t qs, - struct timespec * timeo, + struct timespec * dl, struct irm_flow * f_out, const void * data, size_t len) @@ -1570,7 +1570,7 @@ static int flow_alloc(pid_t pid, free(hash); - state = irm_flow_wait_state(f, FLOW_ALLOCATED, timeo); + state = irm_flow_wait_state(f, FLOW_ALLOCATED, dl); if (state != FLOW_ALLOCATED) { if (state == -ETIMEDOUT) { log_dbg("Flow allocation timed out"); @@ -2075,7 +2075,7 @@ static void * mainloop(void * o) irm_msg_t * ret_msg; struct irm_flow e; struct ipcp_config conf; - struct timespec * timeo = NULL; + struct timespec * dl = NULL; struct timespec ts = {0, 0}; struct cmd * cmd; int result; @@ -2119,11 +2119,16 @@ static void * mainloop(void * o) tpm_dec(irmd.tpm); if (msg->has_timeo_sec) { + struct timespec now; + clock_gettime(PTHREAD_COND_CLOCK, &now); assert(msg->has_timeo_nsec); ts.tv_sec = msg->timeo_sec; ts.tv_nsec = msg->timeo_nsec; - timeo = &ts; + + ts_add(&ts, &now, &ts); + + dl = &ts; } pthread_cleanup_push(__cleanup_close_ptr, &sfd); @@ -2195,7 +2200,7 @@ static void * mainloop(void * o) case IRM_MSG_CODE__IRM_FLOW_ACCEPT: assert(msg->pk.len > 0 ? msg->pk.data != NULL : msg->pk.data == NULL); - result = flow_accept(msg->pid, timeo, &e, + result = flow_accept(msg->pid, dl, &e, msg->pk.data, msg->pk.len); if (result == 0) { ret_msg->has_flow_id = true; @@ -2215,7 +2220,7 @@ static void * mainloop(void * o) : msg->pk.data == NULL); result = flow_alloc(msg->pid, msg->dst, qos_spec_msg_to_s(msg->qosspec), - timeo, &e, msg->pk.data, + dl, &e, msg->pk.data, msg->pk.len); if (result == 0) { ret_msg->has_flow_id = true; @@ -2233,7 +2238,7 @@ static void * mainloop(void * o) assert(msg->pk.len == 0 && msg->pk.data == NULL); result = flow_join(msg->pid, msg->dst, qos_spec_msg_to_s(msg->qosspec), - timeo, &e); + dl, &e); if (result == 0) { ret_msg->has_flow_id = true; ret_msg->flow_id = e.flow_id; diff --git a/src/irmd/proc_table.c b/src/irmd/proc_table.c index 8a25831a..ee87813d 100644 --- a/src/irmd/proc_table.c +++ b/src/irmd/proc_table.c @@ -184,19 +184,13 @@ void proc_entry_del_name(struct proc_entry * e, } int proc_entry_sleep(struct proc_entry * e, - struct timespec * timeo) + struct timespec * dl) { - struct timespec dl; int ret = 0; assert(e); - if (timeo != NULL) { - clock_gettime(PTHREAD_COND_CLOCK, &dl); - ts_add(&dl, timeo, &dl); - } - pthread_mutex_lock(&e->lock); if (e->state != PROC_WAKE && e->state != PROC_DESTROY) @@ -205,8 +199,8 @@ int proc_entry_sleep(struct proc_entry * e, pthread_cleanup_push(cancel_proc_entry, e); while (e->state == PROC_SLEEP && ret != -ETIMEDOUT) - if (timeo) - ret = -pthread_cond_timedwait(&e->cond, &e->lock, &dl); + if (dl != NULL) + ret = -pthread_cond_timedwait(&e->cond, &e->lock, dl); else ret = -pthread_cond_wait(&e->cond, &e->lock); |