From: Alexei Gradinari Date: Wed, 4 Sep 2024 14:28:57 +0000 (-0400) Subject: autoservice: Do not sleep if autoservice_stop is called within autoservice thread X-Git-Tag: 20.10.0-rc1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b270a6ffbfe0f08bd4c8c3e5e08cf41a21a2e0c9;p=thirdparty%2Fasterisk.git autoservice: Do not sleep if autoservice_stop is called within autoservice thread It's possible that ast_autoservice_stop is called within the autoservice thread. In this case the autoservice thread is stuck in an endless sleep. To avoid endless sleep ast_autoservice_stop must check that it's not called within the autoservice thread. Fixes: #763 (cherry picked from commit b11b1f611ce847d61c006296af8e0395244c11bc) --- diff --git a/main/autoservice.c b/main/autoservice.c index 8ff2cb56e1..131075e8d6 100644 --- a/main/autoservice.c +++ b/main/autoservice.c @@ -309,9 +309,16 @@ int ast_autoservice_stop(struct ast_channel *chan) return 0; } - /* Wait while autoservice thread rebuilds its list. */ - while (chan_list_state == as_chan_list_state) { - usleep(1000); + if (asthread != AST_PTHREADT_NULL && pthread_equal(pthread_self(), asthread)) { + /* Do not sleep if ast_autoservice_stop is called within the autoservice thread, + otherwise the thread will be stuck in an endless sleep. */ + ast_debug(1, "ast_autoservice_stop is called within the autoservice thread, channel %s\n", + ast_channel_name(chan)); + } else { + /* Wait while autoservice thread rebuilds its list. */ + while (chan_list_state == as_chan_list_state) { + usleep(1000); + } } /* Now autoservice thread should have no references to our entry