From: Arran Cudbard-Bell Date: Thu, 13 Jul 2023 21:15:15 +0000 (-0600) Subject: atexit: Support checking if the thread is exiting X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7b53e9c4159a920f1fecf0bdb80741cd037771c;p=thirdparty%2Ffreeradius-server.git atexit: Support checking if the thread is exiting --- diff --git a/src/lib/util/atexit.c b/src/lib/util/atexit.c index ecc77065770..2db9335f4a1 100644 --- a/src/lib/util/atexit.c +++ b/src/lib/util/atexit.c @@ -75,6 +75,7 @@ static pthread_mutex_t fr_atexit_global_mutex = PTHREAD_MUTEX_INITIALIZER; static fr_atexit_list_t *fr_atexit_global = NULL; static bool is_exiting; +static _Thread_local bool thread_is_exiting; /** Call the exit handler * @@ -441,6 +442,7 @@ static void _thread_local_pthread_free(void *list) */ static int _thread_local_free(void *list) { + thread_is_exiting = true; return talloc_free(list); } @@ -622,4 +624,12 @@ int fr_atexit_thread_trigger_all(void) return count; } + +/** Return whether the thread is currently being cleaned up + * + */ +bool fr_atexit_thread_is_exiting(void) +{ + return thread_is_exiting; +} #endif diff --git a/src/lib/util/atexit.h b/src/lib/util/atexit.h index 3101af82d9a..77f49d01079 100644 --- a/src/lib/util/atexit.h +++ b/src/lib/util/atexit.h @@ -195,6 +195,8 @@ void fr_atexit_thread_local_disarm_all(void); int fr_atexit_thread_trigger_all(void); +bool fr_atexit_thread_is_exiting(void); + /* * If we're building without threading support, * all this becomes much easier, and we just map