From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Tue, 29 Mar 2022 16:06:25 +0200 Subject: [PATCH] uevent_dispatch(): use while in wait loop Callers of pthread_cond_wait() should generally use a while loop to test the condition. Also, remove the misleading comment. Condition variables aren't unreliable, they're just not strictly tied to the condition tested. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski Signed-off-by: Benjamin Marzinski --- libmultipath/uevent.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c index 80941f87..e3ec1ac1 100644 --- a/libmultipath/uevent.c +++ b/libmultipath/uevent.c @@ -445,13 +445,10 @@ int uevent_dispatch(int (*uev_trigger)(struct uevent *, void * trigger_data), pthread_cleanup_push(cleanup_mutex, uevq_lockp); pthread_mutex_lock(uevq_lockp); servicing_uev = 0; - /* - * Condition signals are unreliable, - * so make sure we only wait if we have to. - */ - if (list_empty(&uevq)) { + + while (list_empty(&uevq)) pthread_cond_wait(uev_condp, uevq_lockp); - } + servicing_uev = 1; list_splice_init(&uevq, &uevq_tmp); pthread_cleanup_pop(1);