From 31e2ab31a61029130fd8be4b2e8abe35bdc19659 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sat, 10 Oct 2020 14:59:14 +0200 Subject: ipcpd: Fix condition variable in flow allocator The condition variable was not initialized correctly and using the wrong clock for pthread_cond_timedwait. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/unicast/fa.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ipcpd/unicast/fa.c b/src/ipcpd/unicast/fa.c index e0727e85..e154d785 100644 --- a/src/ipcpd/unicast/fa.c +++ b/src/ipcpd/unicast/fa.c @@ -274,7 +274,8 @@ static void * fa_handle_packet(void * o) int fa_init(void) { - int i; + pthread_condattr_t cattr; + int i; for (i = 0; i < PROG_MAX_FLOWS; ++i) destroy_conn(i); @@ -285,9 +286,17 @@ int fa_init(void) if (pthread_mutex_init(&fa.mtx, NULL)) goto fail_mtx; - if (pthread_cond_init(&fa.cond, NULL)) + if (pthread_condattr_init(&cattr)) + goto fail_cattr; + +#ifndef __APPLE__ + pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK); +#endif + if (pthread_cond_init(&fa.cond, &cattr)) goto fail_cond; + pthread_condattr_destroy(&cattr); + list_head_init(&fa.cmds); fa.fd = dt_reg_comp(&fa, &fa_post_packet, FA); @@ -295,6 +304,8 @@ int fa_init(void) return 0; fail_cond: + pthread_condattr_destroy(&cattr); + fail_cattr: pthread_mutex_destroy(&fa.mtx); fail_mtx: pthread_rwlock_destroy(&fa.flows_lock); -- cgit v1.2.3