![]() |
Scarab
3.6.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 (std::shared_ptr< cancelable > a_cancelable) |
Add a cancelable object. More... | |
void | remove_cancelable (std::shared_ptr< cancelable > a_cancelable) |
Remove a cancelable object. More... | |
void | remove_cancelable (cancelable *a_cancelable) |
Remove a cancelable object with a plain pointer. 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 (std::shared_ptr< cancelable > a_cancelable) |
Static version: add a cancelable object. More... | |
static void | remove_cancelable_s (std::shared_ptr< cancelable > a_cancelable) |
Static version: remove a cancelable object. More... | |
static void | remove_cancelable_s (cancelable *a_cancelable) |
Static version: remove a cancelable object with a plain pointer. 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::weak_ptr< cancelable > | cancelable_wptr_t |
typedef std::map< cancelable *, cancelable_wptr_t > | 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:
To cleanly exit, signal_handler takes responsibility for canceling the cancelable objects that it knows about. Responsibility for canceling a cancelable is given to the signal_handler using add_cancelable(), and it's taken away using remove_cancelable().
While add_cancelable() takes a std::shared_ptr<cancelable> as an argument, it stores only std::weak_ptr<cancelable>, and claims no ownership or responsibility for the lifetime of the cancelable object.
Definition at line 70 of file signal_handler.hh.
|
private |
Definition at line 119 of file signal_handler.hh.
|
private |
Definition at line 123 of file signal_handler.hh.
|
private |
Definition at line 124 of file signal_handler.hh.
|
private |
Definition at line 125 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 | ( | std::shared_ptr< 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 133 of file signal_handler.cc.
|
static |
Asynchronous call to cancel all cancelables with the given exit code.
Definition at line 300 of file signal_handler.cc.
|
static |
Main exit function – cleanly exits.
Definition at line 235 of file signal_handler.cc.
|
static |
Handler for error signals – cleanly exits.
Definition at line 207 of file signal_handler.cc.
|
static |
Handler for success signals – cleanly exits.
Definition at line 215 of file signal_handler.cc.
|
staticnoexcept |
Handler for std::terminate – does not cleanup memory or threads.
Definition at line 202 of file signal_handler.cc.
|
static |
Prints the current exception, if there is one.
Definition at line 249 of file signal_handler.cc.
|
static |
Prints the stack trace.
Definition at line 275 of file signal_handler.cc.
void remove_cancelable | ( | std::shared_ptr< cancelable > | a_cancelable | ) |
Remove a cancelable object.
void remove_cancelable | ( | scarab::cancelable * | a_cancelable | ) |
Remove a cancelable object with a plain pointer.
Definition at line 127 of file signal_handler.cc.
|
static |
Static version: remove a cancelable object.
|
static |
Static version: remove a cancelable object with a plain pointer.
Definition at line 147 of file signal_handler.cc.
void reset | ( | ) |
Remove all cancelables and signal handling.
Definition at line 154 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 223 of file signal_handler.cc.
|
staticprivate |
Definition at line 127 of file signal_handler.hh.
|
staticprivate |
Definition at line 128 of file signal_handler.hh.