![]() |
Scarab
v3.0.0
Project 8 C++ Utility Library
|
Deals with cleanly exiting an application, and includes signal and std::terminate handler functions. More...
#include <signal_handler.hh>
Public Member Functions | |
signal_handler () | |
virtual | ~signal_handler () |
void | add_cancelable (cancelable *a_cancelable) |
Add a cancelable object. More... | |
void | remove_cancelable (cancelable *a_cancelable) |
Remove a cancelable object. More... | |
void | reset () |
Remove all cancelables and signal handling. More... | |
snake_case_mv_accessible_static_noset (bool, exited) | |
snake_case_mv_accessible_static (int, return_code) | |
snake_case_mv_accessible_static_noset (bool, handling_sig_abrt) | |
snake_case_mv_accessible_static_noset (bool, handling_sig_term) | |
snake_case_mv_accessible_static_noset (bool, handling_sig_int) | |
snake_case_mv_accessible_static_noset (bool, handling_sig_quit) | |
Static Public Member Functions | |
static void | handle_terminate () noexcept |
Handler for std::terminate – does not cleanup memory or threads. More... | |
static void | handle_exit_error (int a_sig) |
Handler for error signals – cleanly exits. More... | |
static void | handle_exit_success (int a_sig) |
Handler for success signals – cleanly exits. More... | |
static void | terminate (int a_code) noexcept |
Main terminate function – does not cleanup memory or threads. More... | |
static void | exit (int a_code) |
Main exit function – cleanly exits. More... | |
static void | print_current_exception (bool a_use_logging) |
Prints the current exception, if there is one. More... | |
static void | print_stack_trace (bool a_use_logging) |
Prints the stack trace. More... | |
static void | cancel_all (int a_code) |
Asynchronous call to cancel all cancelables with the given exit code. More... | |
Private Types | |
typedef std::set< cancelable *> | cancelers |
typedef cancelers::const_iterator | cancelers_cit_t |
typedef cancelers::iterator | cancelers_it_t |
Static Private Attributes | |
static cancelers | s_cancelers |
static std::recursive_mutex | s_mutex |
Deals with cleanly exiting an application, and includes signal and std::terminate handler functions.
This class differentiates between two different ways of finishing a program:
Termination occurs in situations where the program must finish immediately. These are the situations in which std::terminate is used, for example, or there are unhandled exceptions. This can occur during execution, or even during static initialization and cleanup. Therefore only minimal global resources are assumed to be available (e.g. std::cerr). See https://akrzemi1.wordpress.com/2011/10/05/using-stdterminate/ for more information about the way in which termination can be handled. Termination can be commenced by:
Exiting occurs in situations where cleanly shutting down is possible. This includes both successful exiting and exiting with an error condition. signal_handler will be responsible for cancelling all threads that it knows about (via add_cancelable()). After the exit process is complete, it's the responsiblity of the program to stop execution. The program can use get_exited() to check whether the exit process has been used. Exiting can be commenced by:
Definition at line 64 of file signal_handler.hh.
|
private |
Definition at line 104 of file signal_handler.hh.
|
private |
Definition at line 105 of file signal_handler.hh.
|
private |
Definition at line 106 of file signal_handler.hh.
signal_handler | ( | ) |
Definition at line 56 of file signal_handler.cc.
|
virtual |
Definition at line 112 of file signal_handler.cc.
void add_cancelable | ( | scarab::cancelable * | a_cancelable | ) |
Add a cancelable object.
Definition at line 116 of file signal_handler.cc.
|
static |
Asynchronous call to cancel all cancelables with the given exit code.
Definition at line 276 of file signal_handler.cc.
|
static |
Main exit function – cleanly exits.
Definition at line 211 of file signal_handler.cc.
|
static |
Handler for error signals – cleanly exits.
Definition at line 183 of file signal_handler.cc.
|
static |
Handler for success signals – cleanly exits.
Definition at line 191 of file signal_handler.cc.
|
staticnoexcept |
Handler for std::terminate – does not cleanup memory or threads.
Definition at line 178 of file signal_handler.cc.
|
static |
Prints the current exception, if there is one.
Definition at line 225 of file signal_handler.cc.
|
static |
Prints the stack trace.
Definition at line 251 of file signal_handler.cc.
void remove_cancelable | ( | scarab::cancelable * | a_cancelable | ) |
Remove a cancelable object.
Definition at line 123 of file signal_handler.cc.
void reset | ( | ) |
Remove all cancelables and signal handling.
Definition at line 130 of file signal_handler.cc.
snake_case_mv_accessible_static | ( | int | , |
return_code | |||
) |
snake_case_mv_accessible_static_noset | ( | bool | , |
exited | |||
) |
snake_case_mv_accessible_static_noset | ( | bool | , |
handling_sig_abrt | |||
) |
snake_case_mv_accessible_static_noset | ( | bool | , |
handling_sig_term | |||
) |
snake_case_mv_accessible_static_noset | ( | bool | , |
handling_sig_int | |||
) |
snake_case_mv_accessible_static_noset | ( | bool | , |
handling_sig_quit | |||
) |
|
staticnoexcept |
Main terminate function – does not cleanup memory or threads.
Definition at line 199 of file signal_handler.cc.
|
staticprivate |
Definition at line 108 of file signal_handler.hh.
|
staticprivate |
Definition at line 109 of file signal_handler.hh.