Functions to help with cleanup.
More...
#include <stdbool.h>
#include <stdatomic.h>
#include <pthread.h>
#include <freeradius-devel/util/talloc.h>
Go to the source code of this file.
|
typedef int(* | fr_atexit_t) (void *uctx) |
| Destructor callback.
|
|
Functions to help with cleanup.
Simplifies cleaning up thread local and global resources
- Copyright
- 2020-2022 Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)
-
2013-2016 The FreeRADIUS server project
Definition in file atexit.h.
◆ __Thread_local
◆ fr_atexit_global
Add a free function to the global free list.
- Parameters
-
[in] | _func | to call. |
[in] | _uctx | to pass to func. |
- Returns
- 0 on success.
- -1 on failure.
Definition at line 59 of file atexit.h.
◆ fr_atexit_global_once
#define fr_atexit_global_once |
( |
|
_init, |
|
|
|
_free, |
|
|
|
_uctx |
|
) |
| |
Value:do { \
static bool _init_done = false; \
void * _our_uctx = _uctx; \
_init(_our_uctx); \
fr_atexit_global(_free, _our_uctx); \
_init_done = true; \
} \
} while(0);
Definition at line 211 of file atexit.h.
◆ fr_atexit_thread_local
#define fr_atexit_thread_local |
( |
|
_name, |
|
|
|
_free, |
|
|
|
_uctx |
|
) |
| |
Value:do { \
static bool _init_done = false; \
void * _our_uctx = _uctx; \
fr_atexit_global(_free, _our_uctx); \
_init_done = true; \
} \
_name = _our_uctx; \
} while(0);
Definition at line 221 of file atexit.h.
◆ fr_atexit_thread_local_disarm
◆ fr_atexit_thread_local_disarm_all
◆ fr_atexit_thread_trigger_all
#define fr_atexit_thread_trigger_all |
( |
|
... | ) |
|
◆ fr_atexit_t
typedef int(* fr_atexit_t) (void *uctx) |
Destructor callback.
- Parameters
-
- Returns
- 0 on success.
- -1 on failure.
Definition at line 45 of file atexit.h.
◆ _atexit_global()
int _atexit_global |
( |
char const * |
file, |
|
|
int |
line, |
|
|
fr_atexit_t |
func, |
|
|
void const * |
uctx |
|
) |
| |
Add a free function to be called when the process exits.
Definition at line 210 of file atexit.c.
◆ fr_atexit_global_disarm()
unsigned int fr_atexit_global_disarm |
( |
bool |
uctx_scope, |
|
|
fr_atexit_t |
func, |
|
|
void const * |
uctx |
|
) |
| |
Remove a specific global destructor (without executing it)
- Note
- This function's primary purpose is to help diagnose issues with destructors from within a debugger.
- Parameters
-
[in] | uctx_scope | Only process entries where the func and scope both match. |
[in] | func | Entries matching this function will be disarmed. |
[in] | uctx | associated with the entry. |
- Returns
- How many global destructors were disarmed.
Definition at line 229 of file atexit.c.
◆ fr_atexit_global_disarm_all()
void fr_atexit_global_disarm_all |
( |
void |
| ) |
|
Remove all global destructors (without executing them)
- Note
- This function's primary purpose is to help diagnose issues with destructors from within a debugger.
Definition at line 259 of file atexit.c.
◆ fr_atexit_global_setup()
int fr_atexit_global_setup |
( |
void |
| ) |
|
Setup the atexit handler, should be called at the start of a program's execution.
Definition at line 160 of file atexit.c.
◆ fr_atexit_global_trigger_all()
int fr_atexit_global_trigger_all |
( |
void |
| ) |
|
Cause all global free triggers to fire.
This is necessary when libraries (perl) register their own atexit handlers using the normal POSIX mechanism, and we need to ensure all our atexit handlers fire before so any global deinit is done explicitly by us.
- Returns
- >= 0 The number of atexit handlers triggered on success.
- <0 the return code from any atexit handlers that returned an error.
Definition at line 286 of file atexit.c.
◆ fr_atexit_is_exiting()
bool fr_atexit_is_exiting |
( |
void |
| ) |
|
Return whether we're currently in the teardown phase.
When this function returns true no more thread local or global destructors can be added.
Definition at line 412 of file atexit.c.
◆ fr_atexit_trigger()
int fr_atexit_trigger |
( |
bool |
uctx_scope, |
|
|
fr_atexit_t |
func, |
|
|
void const * |
uctx |
|
) |
| |
Iterates through all thread local destructor lists, causing destructor to be triggered.
This should only be called by the main process not by threads.
The main purpose of the function is to force cleanups at a specific time for problematic destructors.
- Parameters
-
[in] | uctx_scope | Only process entries where the func and scope both match. |
[in] | func | Entries matching this function will be triggered. |
[in] | uctx | associated with the entry. |
- Returns
- >= 0 The number of atexit handlers triggered on success.
- <0 the return code from any atexit handlers that returned an error.
Definition at line 331 of file atexit.c.