From 3b2f38aeafa1d6d2976dd5581ef46a5d3b463825 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Tue, 14 Mar 2023 12:50:26 +0100 Subject: 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 Signed-off-by: Sander Vrijders --- src/irmd/irm_flow.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/irmd/irm_flow.c') 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 || -- cgit v1.2.3