Macros to abstract Thread Local Storage.
More...
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/dlist.h>
#include <freeradius-devel/util/atexit.h>
Go to the source code of this file.
|
static int | _atexit_entry_free (fr_atexit_entry_t *e) |
| Call the exit handler. More...
|
|
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. More...
|
|
static int | _destructor_list_free (fr_atexit_list_t *list) |
| Talloc destructor for freeing list elements in order. More...
|
|
static void | _global_free (void) |
| Free any thread-local exit handler lists that pthread_key failed to fre. More...
|
|
static fr_atexit_entry_t * | atexit_entry_alloc (char const *file, int line, fr_atexit_list_t *list, fr_atexit_t func, void const *uctx) |
| Allocate a new exit handler entry. More...
|
|
unsigned int | fr_atexit_global_disarm (bool uctx_scope, fr_atexit_t func, void const *uctx) |
| Remove a specific global destructor (without executing it) More...
|
|
void | fr_atexit_global_disarm_all (void) |
| Remove all global destructors (without executing them) More...
|
|
int | fr_atexit_global_setup (void) |
| Setup the atexit handler, should be called at the start of a program's execution. More...
|
|
int | fr_atexit_global_trigger_all (void) |
| Cause all global free triggers to fire. More...
|
|
bool | fr_atexit_is_exiting (void) |
| Return whether we're currently in the teardown phase. More...
|
|
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. More...
|
|
Macros to abstract Thread Local Storage.
Simplifies calling thread local destructors (called when the thread exits).
- Copyright
- 2020-2021 Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)
-
2020 The FreeRADIUS server project
Definition in file atexit.c.
◆ fr_atexit_entry_t
Entry in exit handler list.
Definition at line 48 of file atexit.c.
Data Fields |
fr_dlist_t |
entry |
Entry in the handler dlist. |
char const * |
file |
File where this exit handler was added. |
fr_atexit_t |
func |
Function to call. |
int |
line |
Line where this exit handler was added. |
fr_atexit_list_t * |
list |
List this entry is in. |
void * |
uctx |
uctx to pass. |
◆ fr_exit_handler_list_s
struct fr_exit_handler_list_s |
Head of a list of exit handlers.
Definition at line 62 of file atexit.c.
Data Fields |
fr_atexit_entry_t * |
e |
Inserted into the global exit handler list to ensure this memory is cleaned up. |
fr_dlist_head_t |
head |
Head of the list of destructors. |
pthread_key_t |
key |
Key used to trigger thread local destructors. |
◆ ATEXIT_DEBUG
◆ CHECK_GLOBAL_SETUP
#define CHECK_GLOBAL_SETUP |
( |
| ) |
|
Value:do { \
int _ret = 0; \
fr_cond_assert_msg(!
is_exiting,
"New atexit handlers should not be allocated whilst exiting"); \
static fr_atexit_list_t * fr_atexit_global
int fr_atexit_global_setup(void)
Setup the atexit handler, should be called at the start of a program's execution.
Definition at line 198 of file atexit.c.
◆ fr_atexit_list_t
◆ _atexit_entry_free()
Call the exit handler.
Definition at line 83 of file atexit.c.
◆ _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.
◆ _destructor_list_free()
Talloc destructor for freeing list elements in order.
Definition at line 130 of file atexit.c.
◆ _global_free()
static void _global_free |
( |
void |
| ) |
|
|
static |
Free any thread-local exit handler lists that pthread_key failed to fre.
Definition at line 141 of file atexit.c.
◆ atexit_entry_alloc()
Allocate a new exit handler entry.
Definition at line 102 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.
◆ fr_atexit_global
◆ is_exiting
◆ thread_is_exiting
_Thread_local bool thread_is_exiting |
|
static |