From 831ef27b41858fa248201b74f2dd8ea5b7c4aece Mon Sep 17 00:00:00 2001
From: Martin Wilck <mwilck@suse.com>
Date: Sat, 10 Feb 2018 00:22:17 +0100
Subject: [PATCH] tur checker: make sure pthread_cancel isn't called for exited
thread
If we enter the cleanup function as the result of a pthread_cancel by another
thread, we don't need to wait for a cancellation any more. If we exit
regularly, just tell the other thread not to try to cancel us.
---
libmultipath/checkers/tur.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
@@ -221,8 +221,6 @@ static void cleanup_func(void *data)
holders = uatomic_sub_return(&ct->holders, 1);
if (!holders)
cleanup_context(ct);
- if (!running)
- pause();
}
static int tur_running(struct tur_checker_context *ct)
@@ -266,6 +264,9 @@ static void *tur_thread(void *ctx)
pthread_cond_signal(&ct->active);
pthread_mutex_unlock(&ct->lock);
+ /* Tell main checker thread not to cancel us, as we exit anyway */
+ running = uatomic_xchg(&ct->running, 0);
+
condlog(3, "%s: tur checker finished, state %s",
tur_devt(devt, sizeof(devt), ct), checker_state_name(state));
tur_thread_cleanup_pop(ct);
--
2.16.1