From 6523e4ea312632f593a9f1a25b2c364b4b39db4a Mon Sep 17 00:00:00 2001
From: Grzegorz Sluja <grzegorz.sluja@iopsys.eu>
Date: Thu, 22 Jul 2021 12:11:58 +0200
Subject: [PATCH] Fix stopping ubus thread during unloading chan_brcm.so module

When chan_brcm.so module is unloading we are trying to stop the ubus
thread. With pthread_cancel() called before pthread_join() we are hanging
for a long time since the thread has not set cancellation type. The
cancellation type 'deferred' is set by default what means that
cancellation is delayed until the thread next call, that takes time.
Using pthread_kill() instead of pthread_cancel() makes the signal is sent
to the thread immediately causing thread exits/joins suddenly.
---
 channels/chan_brcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/channels/chan_brcm.c b/channels/chan_brcm.c
index 9eb146a7f4..b995dd962b 100644
--- a/channels/chan_brcm.c
+++ b/channels/chan_brcm.c
@@ -3201,7 +3201,7 @@ static int unload_module(void)
 	if (!ast_mutex_lock(&monlock)) {
 		if (ubus_thread != AST_PTHREADT_NULL && ubus_thread != AST_PTHREADT_STOP) {
 			ast_verbose("Stopping ubus thread...\n");
-			pthread_cancel(ubus_thread);
+			pthread_kill(ubus_thread, SIGUSR2);
 			pthread_join(ubus_thread, NULL);
 			ubus_thread = AST_PTHREADT_STOP;
 			ast_verbose("ubus thread is stopped\n");
-- 
GitLab