Provides serialised handler execution. More...
#include <strand.hpp>
Public Member Functions | |
template<typename Handler > | |
void | dispatch (Handler handler) |
Request the strand to invoke the given handler. | |
asio::io_service & | get_io_service () |
Get the io_service associated with the strand. | |
asio::io_service & | io_service () |
template<typename Handler > | |
void | post (Handler handler) |
strand (asio::io_service &io_service) | |
Constructor. | |
template<typename Handler > | |
detail::wrapped_handler < strand, Handler > | wrap (Handler handler) |
~strand () | |
Destructor. | |
Private Attributes | |
asio::detail::strand_service::implementation_type | impl_ |
asio::detail::strand_service & | service_ |
Provides serialised handler execution.
The io_service::strand class provides the ability to post and dispatch handlers with the guarantee that none of those handlers will execute concurrently.
Definition at line 39 of file strand.hpp.
asio::io_service::strand::strand | ( | asio::io_service & | io_service | ) | [inline, explicit] |
Constructor.
Constructs the strand.
io_service | The io_service object that the strand will use to dispatch handlers that are ready to be run. |
Definition at line 49 of file strand.hpp.
asio::io_service::strand::~strand | ( | ) | [inline] |
Destructor.
Destroys a strand.
Handlers posted through the strand that have not yet been invoked will still be dispatched in a way that meets the guarantee of non-concurrency.
Definition at line 63 of file strand.hpp.
void asio::io_service::strand::dispatch | ( | Handler | handler | ) | [inline] |
Request the strand to invoke the given handler.
This function is used to ask the strand to execute the given handler.
The strand object guarantees that handlers posted or dispatched through the strand will not be executed concurrently. The handler may be executed inside this function if the guarantee can be met. If this function is called from within a handler that was posted or dispatched through the same strand, then the new handler will be executed immediately.
The strand's guarantee is in addition to the guarantee provided by the underlying io_service. The io_service guarantees that the handler will only be called in a thread in which the io_service's run member function is currently being invoked.
handler | The handler to be called. The strand will make a copy of the handler object as required. The function signature of the handler must be: void handler();
|
Definition at line 115 of file strand.hpp.
asio::io_service& asio::io_service::strand::get_io_service | ( | ) | [inline] |
Get the io_service associated with the strand.
This function may be used to obtain the io_service object that the strand uses to dispatch handlers for asynchronous operations.
Definition at line 90 of file strand.hpp.
asio::io_service& asio::io_service::strand::io_service | ( | ) | [inline] |
(Deprecated: use get_io_service().) Get the io_service associated with the strand. This function may be used to obtain the io_service object that the strand uses to dispatch handlers for asynchronous operations.
Definition at line 77 of file strand.hpp.
void asio::io_service::strand::post | ( | Handler | handler | ) | [inline] |
Request the strand to invoke the given handler and return immediately. This function is used to ask the strand to execute the given handler, but without allowing the strand to call the handler from inside this function.
The strand object guarantees that handlers posted or dispatched through the strand will not be executed concurrently. The strand's guarantee is in addition to the guarantee provided by the underlying io_service. The io_service guarantees that the handler will only be called in a thread in which the io_service's run member function is currently being invoked.
handler | The handler to be called. The strand will make a copy of the handler object as required. The function signature of the handler must be: void handler();
|
Definition at line 137 of file strand.hpp.
detail::wrapped_handler<strand, Handler> asio::io_service::strand::wrap | ( | Handler | handler | ) | [inline] |
Create a new handler that automatically dispatches the wrapped handler on the strand. This function is used to create a new handler function object that, when invoked, will automatically pass the wrapped handler to the strand's dispatch function.
handler | The handler to be wrapped. The strand will make a copy of the handler object as required. The function signature of the handler must be: void handler(A1 a1, ... An an);
|
R f(A1 a1, ... An an);
strand.wrap(f);
void g(A1 a1, ... An an);
strand.dispatch(boost::bind(f, a1, ... an));
Definition at line 169 of file strand.hpp.
Definition at line 176 of file strand.hpp.
Definition at line 175 of file strand.hpp.