SObjectizer-5 Extra
Namespaces | Classes | Functions
so_5::extra::shutdowner Namespace Reference

Namespaces

 details
 
 errors
 

Classes

class  layer_t
 An interface of shutdowner layer. More...
 
struct  shutdown_initiated_t
 A message to be used to inform about start of shutdown operation. More...
 

Functions

template<typename Lock_Type = std::mutex>
std::unique_ptr< ::so_5::extra::shutdowner::layer_tmake_layer (std::chrono::steady_clock::duration shutdown_max_time)
 Main function to create an instance of shutdowner layer. More...
 
inline ::so_5::extra::shutdowner::layer_tlayer (::so_5::environment_t &env)
 A helper function to receive a reference to shutdowner layer. More...
 

Function Documentation

◆ layer()

inline ::so_5::extra::shutdowner::layer_t& so_5::extra::shutdowner::layer ( ::so_5::environment_t &  env)

A helper function to receive a reference to shutdowner layer.

Usage example:

// To make a subscription to shutdown notification.
class my_agent final : public so_5::agent_t {
public :
my_agent(context_t ctx) : so_5::agent_t(std::move(ctx)) {
auto & s = so_5::extra::shutdowner::layer( so_environment() );
so_subscribe( s.notify_mbox() ).event( &my_agent::on_shutdown );
...
}
...
private :
void on_shutdown(mhood_t<so_5::extra::shutdowner::shutdown_initiated_t>)
{...}
};
// To initiate shutdown.
so_5::extra::shutdowner::layer(env).initiate_shutdown();
Note
May throw an exception if shutdowner layer is not defined.
Examples:
shutdowner/simple/main.cpp.

Definition at line 891 of file shutdowner.hpp.

◆ make_layer()

template<typename Lock_Type = std::mutex>
std::unique_ptr< ::so_5::extra::shutdowner::layer_t > so_5::extra::shutdowner::make_layer ( std::chrono::steady_clock::duration  shutdown_max_time)

Main function to create an instance of shutdowner layer.

Usage example:

// Creation of layer with default mutex type.
so_5::launch([](so_5::environment_t & env) {...},
[](so_5::environment_params_t & params) {
params.add_layer( so_5::extra::shutdowner::make_layer<>(30s) );
});
// Creation of layer with user-provided spinlock type.
so_5::launch([](so_5::environment_t & env) {...},
[](so_5::environment_params_t & params) {
params.add_layer( so_5::extra::shutdowner::make_layer<my_spinlock_t>(30s));
});
// Creation of layer with null_mutex.
// Note: null_mutex must be used only for non thread-safe environments.
so_5::launch([](so_5::environment_t & env) {...},
[](so_5::environment_params_t & params) {
// Use single-threaded and not thread-safe environment.
params.infrastructure_factory(
// Shutdowner layer with null_mutex can be used in that environment.
params.add_layer( so_5::extra::shutdowner::make_layer<so_5::null_mutex_t>(30s));
});
Template Parameters
Lock_Typetype of lock to be used for thread safety.
Parameters
shutdown_max_timeA maximum time for timeout operation.

Definition at line 851 of file shutdowner.hpp.