]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
More, minor, atexit cleanups
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 5 Jan 2022 02:09:15 +0000 (20:09 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 5 Jan 2022 02:09:15 +0000 (20:09 -0600)
src/lib/util/atexit.c
src/lib/util/atexit.h
src/lib/util/event.c

index 45ebb953c7d77dd5308bf0b3d5f90c06e6afba40..c880c0635b1d79cb0452af90cf7e1282b0cf77d3 100644 (file)
@@ -358,7 +358,7 @@ void fr_atexit_thread_local_disarm_all(void)
  * @param[in] uctx             associated with the entry.
  * @return How many global destructors were disarmed.
  */
-unsigned int fr_atexit_disarm(bool uctx_scope, fr_atexit_t func, void const *uctx)
+unsigned int fr_atexit_global_disarm(bool uctx_scope, fr_atexit_t func, void const *uctx)
 {
        fr_atexit_entry_t       *e = NULL;
        unsigned int            count = 0;
@@ -390,7 +390,7 @@ unsigned int fr_atexit_disarm(bool uctx_scope, fr_atexit_t func, void const *uct
  * @note This function's primary purpose is to help diagnose issues with destructors
  *      from within a debugger.
  */
-void fr_atexit_disarm_all(void)
+void fr_atexit_global_disarm_all(void)
 {
        fr_atexit_entry_t *e = NULL;
 
index 57f14c162986ef55eb89612577a586e582380f3d..b4b0a767cc47294aac8bd83083740a35c94583d5 100644 (file)
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-/** Functions to help with thread local destructors
+/** Functions to help with cleanup
  *
- * Simplifies calling thread local destructors (called when the thread exits).
+ * Simplifies cleaning up thread local and global resources
  *
  * @file lib/util/atexit.h
  *
- * @copyright 2020-2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
+ * @copyright 2020-2022 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
  * @copyright 2013-2016 The FreeRADIUS server project
  */
 RCSIDH(atexit_h, "$Id$")
@@ -74,16 +74,17 @@ int _atexit_global(NDEBUG_LOCATION_ARGS fr_atexit_t func, void const *uctx);
  *                             during the process lifetime.
  * @param[in] _free            function to call. Will be called once
  *                             at exit.
+ * @param[in] _uctx            data to be passed to free function.
  */
-#define fr_atexit_global_once(_init, _free) \
+#define fr_atexit_global_once(_init, _free, _uctx) \
 { \
        static atomic_bool      _init_done = false; \
        static pthread_mutex_t  _init_mutex = PTHREAD_MUTEX_INITIALIZER; \
        if (unlikely(!atomic_load(&_init_done))) { \
                pthread_mutex_lock(&_init_mutex); \
                if (!atomic_load(&_init_done)) { \
-                       _init(); \
-                       atexit(_free); \
+                       _init(_uctx); \
+                       fr_atexit_global(_free, _uctx); \
                        atomic_store(&_init_done, true); \
                } \
                pthread_mutex_unlock(&_init_mutex); \
@@ -96,25 +97,26 @@ int _atexit_global(NDEBUG_LOCATION_ARGS fr_atexit_t func, void const *uctx);
  *     destroyed.  So we need to store the address of the memory to free, not
  *     the address of the thread local variable.
  *
- * @param _n   Name of variable e.g. 'my_tls'.
- * @param _f   Destructor, called when the thread exits to clean up any data.
- * @param _v   Memory to free.
+ * @param[in] _name            Name of variable e.g. 'my_tls'.
+ * @param[in] _free            Destructor, called when the thread exits to clean up any data.
+ * @param[in] _uctx            Memory to free.
  */
-#  define fr_atexit_thread_local(_n, _f, _v) \
+#  define fr_atexit_thread_local(_name, _free, _uctx) \
 do { \
-       _fr_atexit_thread_local(NDEBUG_LOCATION_EXP _f, _v); \
-       _n = _v; \
+       _fr_atexit_thread_local(NDEBUG_LOCATION_EXP _free, _uctx); \
+       _name = _uctx; \
 } while (0);
-int    _fr_atexit_thread_local(NDEBUG_LOCATION_ARGS
-                               fr_atexit_t func, void const *uctx);
+
+int            _fr_atexit_thread_local(NDEBUG_LOCATION_ARGS
+                                       fr_atexit_t func, void const *uctx);
 
 unsigned int   fr_atexit_thread_local_disarm(bool uctx_scope, fr_atexit_t func, void const *uctx);
 
 void           fr_atexit_thread_local_disarm_all(void);
 
-unsigned int   fr_atexit_disarm(bool uctx_scope, fr_atexit_t func, void const *uctx);
+unsigned int   fr_atexit_global_disarm(bool uctx_scope, fr_atexit_t func, void const *uctx);
 
-void           fr_atexit_disarm_all(void);
+void           fr_atexit_global_disarm_all(void);
 
 unsigned int   fr_atexit_trigger(bool uctx_scope, fr_atexit_t func, void const *uctx);
 
index 45b281c26171b8e577565d654e6c1ca4a0597d2c..fa1e63e687211e0f04cdf712ad6c39cd5503b2e0 100644 (file)
@@ -2583,14 +2583,14 @@ static int _event_list_free(fr_event_list_t *el)
 /** Free any memory we allocated for indexes
  *
  */
-static void _event_free_indexes(void)
+static void _event_free_indexes(UNUSED void *uctx)
 {
        unsigned int i;
 
        for (i = 0; i < NUM_ELEMENTS(filter_maps); i++) talloc_free(filter_maps[i].ev_to_func);
 }
 
-static void _event_build_indexes(void)
+static void _event_build_indexes(UNUSED void *uctx)
 {
        unsigned int i;
 
@@ -2615,7 +2615,7 @@ fr_event_list_t *fr_event_list_alloc(TALLOC_CTX *ctx, fr_event_status_cb_t statu
         *      Build the map indexes the first time this
         *      function is called.
         */
-       fr_atexit_global_once(_event_build_indexes, _event_free_indexes);
+       fr_atexit_global_once(_event_build_indexes, _event_free_indexes, NULL);
 
        el = talloc_zero(ctx, fr_event_list_t);
        if (!fr_cond_assert(el)) {