![]() |
Scarab
v3.4.2
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 | add_cancelable_s (cancelable *a_cancelable) |
Static version: add a cancelable object. More... | |
static void | remove_cancelable_s (cancelable *a_cancelable) |
Static version: remove a cancelable object. More... | |
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 109 of file signal_handler.hh.
|
private |
Definition at line 110 of file signal_handler.hh.
|
private |
Definition at line 111 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 115 of file signal_handler.cc.
|
static |
Static version: add a cancelable object.
Definition at line 127 of file signal_handler.cc.
|
static |
Asynchronous call to cancel all cancelables with the given exit code.
Definition at line 287 of file signal_handler.cc.
|
static |
Main exit function – cleanly exits.
Definition at line 222 of file signal_handler.cc.
|
static |
Handler for error signals – cleanly exits.
Definition at line 194 of file signal_handler.cc.
|
static |
Handler for success signals – cleanly exits.
Definition at line 202 of file signal_handler.cc.
|
staticnoexcept |
Handler for std::terminate – does not cleanup memory or threads.
Definition at line 189 of file signal_handler.cc.
|
static |
Prints the current exception, if there is one.
Definition at line 236 of file signal_handler.cc.
|
static |
Prints the stack trace.
Definition at line 262 of file signal_handler.cc.
void remove_cancelable | ( | scarab::cancelable * | a_cancelable | ) |
Remove a cancelable object.
Definition at line 121 of file signal_handler.cc.
|
static |
Static version: remove a cancelable object.
Definition at line 134 of file signal_handler.cc.
void reset | ( | ) |
Remove all cancelables and signal handling.
Definition at line 141 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 210 of file signal_handler.cc.
|
staticprivate |
Definition at line 113 of file signal_handler.hh.
|
staticprivate |
Definition at line 114 of file signal_handler.hh.