#include <icy/synchronizer.h>Inherits:
Runner
Synchronizer enables any thread to communicate with the associated event loop via synchronized callbacks.
This class inherits the [Runner](icy-Runner.html#runner) interface and may be used with any implementation that's powered by an asynchronous [Runner](icy-Runner.html#runner).
| Return | Name | Description |
|---|---|---|
Synchronizer | Creates a synchronizer attached to the given event loop without a callback. Call [start()](#start-5) separately to register the callback before using [post()](#post). | |
Synchronizer | Creates and immediately starts a synchronizer with a single callback function. The target is invoked from the event loop context each time [post()](#post) is called. | |
Synchronizer inline explicit | Creates and immediately starts a synchronizer with a variadic callback. | |
~Synchronizer virtual | Destructor. | |
void | post | Send a synchronization request to the event loop. Call this each time you want the target method called synchronously. The synchronous method will be called on next iteration. This is not atomic, so do not expect a callback for every request. |
void | start inline | Starts the synchronizer with a variadic callback function. The callback is invoked from the event loop each time [post()](#post) is called. Throws std::logic_error if already running or if the handle is null. |
void | start virtual | Starts the synchronizer with a std::function callback. Overrides [Runner::start](icy-Runner.html#start-3); delegates to the variadic start template. |
void | cancel virtual | Cancels the synchronizer, signalling the associated callback to stop. A subsequent [post()](#post) is needed to wake up the event loop so it can process the cancellation. |
void | close virtual | Cancels the synchronizer and closes the underlying uv_async_t handle. Safe to call multiple times; no-op if already closed. |
uv::Handle< uv_async_t > & | handle | Returns a reference to the underlying libuv async handle. |
Synchronizer(uv::Loop * loop)Creates a synchronizer attached to the given event loop without a callback. Call [start()](#start-5) separately to register the callback before using [post()](#post).
loop Event loop to attach the async handle to.Synchronizer(std::function< void()> target, uv::Loop * loop)Creates and immediately starts a synchronizer with a single callback function. The target is invoked from the event loop context each time [post()](#post) is called.
target Callback to invoke on each event loop wakeup.
loop Event loop to attach the async handle to.
inline explicit
template<typename Function, typename... Args> inline explicit Synchronizer(Function && func, Args &&... args, uv::Loop * loop)Creates and immediately starts a synchronizer with a variadic callback.
Function Callable type.
Args Argument types forwarded to the function.
func Callable to invoke on each event loop wakeup.
args Arguments forwarded to func.
loop Event loop to attach the async handle to.
virtual
virtual ~Synchronizer()Destructor.
void post()Send a synchronization request to the event loop. Call this each time you want the target method called synchronously. The synchronous method will be called on next iteration. This is not atomic, so do not expect a callback for every request.
inline
template<typename Function, typename... Args> inline void start(Function && func, Args &&... args)Starts the synchronizer with a variadic callback function. The callback is invoked from the event loop each time [post()](#post) is called. Throws std::logic_error if already running or if the handle is null.
Function Callable type.
Args Argument types forwarded to the function.
func Callable to invoke on each event loop wakeup.
args Arguments forwarded to func.
virtual
virtual void start(std::function< void()> func)Starts the synchronizer with a std::function callback. Overrides [Runner::start](icy-Runner.html#start-3); delegates to the variadic start template.
func Callback invoked from the event loop on each [post()](#post) call.virtual
virtual void cancel()Cancels the synchronizer, signalling the associated callback to stop. A subsequent [post()](#post) is needed to wake up the event loop so it can process the cancellation.
virtual
virtual void close()Cancels the synchronizer and closes the underlying uv_async_t handle. Safe to call multiple times; no-op if already closed.
uv::Handle< uv_async_t > & handle()Returns a reference to the underlying libuv async handle.
Reference to the [uv::Handle](icy-uv-Handle.html#handle-6)<uv_async_t>.
| Return | Name | Description |
|---|---|---|
uv::Handle< uv_async_t > | _handle |
uv::Handle< uv_async_t > _handle| Return | Name | Description |
|---|---|---|
bool | async virtual const | Returns true if the implementation is thread-based. |
virtual const
virtual bool async() constReturns true if the implementation is thread-based.
True for thread-backed runners, false for event-loop-driven runners.