Repository navigation
life_assurance
A policy that defines how the signal/listenable handlers life control is being performed. This topic is only covered at the Rationale page, exactly here and here.
namespace life_assurance
{
struct intrusive_life_tokens;
struct single_threaded;
struct none;
}
-
Supplied policies
- intrusive_life_tokens (default)
- single_threaded
- none
- How to implement your own policy
This policy uses the same internals as life_tokens for signal handler validity control, but is more efficient in terms of memory and CPU usage.
It is guaranteed that the execution flow is out of the handler after the token destructor. The token destructor blocks if the handler is being executed at the moment of disconnecting.
This policy is good for the case where you access a signal from a single task_executor, but still use async handlers (processed in the same task_executor!).
It is guaranteed that the async handler will not start executing after the token destructor. However, the token destructor does not block if the handler is being executed in another thread at the moment of disconnecting.
A no-overhead policy, good for single-threaded signals.
struct my_life_assurance
{
using tag = wigwag::life_assurance::tag<wigwag::api_version<2, 0>>;
class shared_data
{ };
struct life_assurance
{
void release_life_assurance(const shared_data& sd) { /*...*/ }
bool node_should_be_released() const { /*...*/ }
bool release_node() const { /*...*/ }
};
struct life_checker
{
life_checker(const shared_data& sd, const life_assurance& la) { /*...*/ }
};
struct execution_guard
{
execution_guard(const life_checker& lc) { /*...*/ }
execution_guard(const shared_data& sd, const life_assurance& la) { /*...*/ }
bool is_alive() const { /*...*/ }
};
};using tag = wigwag::life_assurance::tag<wigwag::api_version<2, 0>>;The policy tag. Must be a type alias for wigwag::life_assurance::tag<wigwag::api_version<2, 0>>.
class shared_data
{ /*...*/ };A shared_data object is stored inside a signal, and may hold any objects that are shared between different signal handlers.
struct life_assurance
{
void release_life_assurance(const shared_data& sd) { /*...*/ }
bool node_should_be_released() const { /*...*/ }
bool release_node() const { /*...*/ }
};A life_assurance object is stored inside a signal connection token, and is used to control the validity of the handler.
struct life_checker
{
life_checker(const shared_data& sd, const life_assurance& la) { /*...*/ }
};A life_checker object is held inside the async handler internals, and references a life_assurance object that will be locked using the execution_guard.
struct execution_guard
{
execution_guard(const life_checker& lc) { /*...*/ }
execution_guard(const shared_data& sd, const life_assurance& la) { /*...*/ }
bool is_alive() const { /*...*/ }
};An execution_guard object is created locally for the handler execution time, and is used for checking if the handler is still valid and blocking the signal connection token destructor.
life_assurance();A default constructor is used to create a new life_assurance object in the signal::connect() method.
void release_life_assurance();This method is invoked when disconnecting from a signal.
Any subsequent execution_guard::is_alive() calls should return false, and the method should block if there are any associated execution_guards objects until these objects are destroyed.
bool node_should_be_released() const;This method checks if the signal has the last and only reference to a signal handler node and should release it.
Return value: true if a signal should invoke release_node from the signal::operator (), false otherwise
bool release_node() const;This method checks if there are no more references to a signal handler node, and it may be deleted.
Return value: true if the a signal handler node should be deleted, false otherwise
life_checker(const shared_data& sd, const life_assurance& la);Constructs a life_checker object.
Arguments:
- sd - a reference to a const shared_data object
- la - a reference to a const life_assurance object
execution_guard(const life_checker& lc);Should lock the life_assurance object, so that its destructor would block if invoked.
Arguments:
- lc - a reference to a const life_checker object
execution_guard(const shared_data& sd, const life_assurance& la);Should lock the life_assurance object, so that its destructor would block if invoked.
Arguments:
- sd - a reference to a const shared_data object
- la - a reference to a const life_assurance object
~execution_guard();Should unlock the life_assurance object, so that its destructor would return if was blocked.
bool is_alive() const;This method should return false after a life_assurance::release() call, true otherwise.
Return value: true if it is safe to invoke the signal handler, false otherwise