]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Allow disarming of atexit thread-local destructors
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 12 Feb 2021 21:07:30 +0000 (21:07 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 12 Feb 2021 21:27:30 +0000 (21:27 +0000)
src/lib/util/thread_local.c
src/lib/util/thread_local.h

index 3671140a146d97ac12956c4bdab0caac29be3f6b..afea1837388a636cb253b5d245ea44655e090ab1 100644 (file)
@@ -221,3 +221,25 @@ int fr_thread_local_atexit(fr_thread_local_atexit_t func, void const *uctx)
        return 0;
 }
 
+/** Remove destructor
+ *
+ * @return
+ *     - 0 on success.
+ *      - -1 if function and uctx could not be found.
+ */
+int fr_thread_local_atexit_disarm(fr_thread_local_atexit_t func, void const *uctx)
+{
+       fr_exit_handler_entry_t *e = NULL;
+
+       while ((e = fr_dlist_next(&thread_local_atexit->head, e))) {
+               if ((e->func == func) && (e->uctx == uctx)) {
+                       fr_dlist_remove(&thread_local_atexit->head, e);
+                       talloc_set_destructor(e, NULL);
+                       talloc_free(e);
+                       return 0;
+               }
+       }
+
+       return -1;
+}
+
index c3adab351344a8ac6acd490b9d0ec896949aad65..308bc1fda1d595b8a20dddfa59f34ef3d4afcdd7 100644 (file)
@@ -42,6 +42,8 @@ int fr_thread_local_atexit_setup(void);
 
 int fr_thread_local_atexit(fr_thread_local_atexit_t func, void const *uctx);
 
+int fr_thread_local_atexit_disarm(fr_thread_local_atexit_t func, void const *uctx);
+
 /** Set a destructor for thread local storage to free the memory on thread exit
  *
  * @note Pointers to thread local storage seem to become unusable as threads are