]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
atexit: Support checking if the thread is exiting
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 13 Jul 2023 21:15:15 +0000 (15:15 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 13 Jul 2023 21:17:56 +0000 (15:17 -0600)
src/lib/util/atexit.c
src/lib/util/atexit.h

index ecc77065770270e916a0f200da2af348a4780996..2db9335f4a1be88bfefd5572448c447fb2a4e38f 100644 (file)
@@ -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
index 3101af82d9ad3d0ea23c2ee773a92e3bf4b4c81d..77f49d010794bf6dfa4a9ebb113e2caf3dba6511 100644 (file)
@@ -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