Synchronizer
Synchronizer
#include <icy/synchronizer.h>class SynchronizerDefined in src/base/include/icy/synchronizer.h:38
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).
List of all members
| Name | Kind | Owner |
|---|---|---|
Synchronizer | function | Declared here |
Synchronizer | function | Declared here |
Synchronizer | function | Declared here |
~Synchronizer | function | Declared here |
post | function | Declared here |
start | function | Declared here |
start | function | Declared here |
cancel | function | Declared here |
close | function | Declared here |
handle | function | Declared here |
_handle | variable | Declared here |
async | function | Declared here |
Runner | function | Inherited from Runner |
~Runner | function | Inherited from Runner |
start | function | Inherited from Runner |
running | function | Inherited from Runner |
cancel | function | Inherited from Runner |
cancelled | function | Inherited from Runner |
repeating | function | Inherited from Runner |
setRepeating | function | Inherited from Runner |
async | function | Inherited from Runner |
tid | function | Inherited from Runner |
waitForExit | function | Inherited from Runner |
_context | variable | Inherited from Runner |
Runner | function | Inherited from Runner |
operator= | function | Inherited from Runner |
Runner | function | Inherited from Runner |
operator= | function | Inherited from Runner |
Inherited from Runner
| Kind | Name | Description |
|---|---|---|
function | Runner | |
function | ~Runner virtual | |
function | start virtual | Starts the asynchronous context with the given callback. The callback must remain valid for the lifetime of the [Runner](icy-Runner.html#runner). |
function | running const | Returns true if the async context is currently running. |
function | cancel | Signals the async context to stop at the earliest opportunity. |
function | cancelled const | Returns true if the context has been cancelled. The implementation is responsible for exiting as soon as possible after cancellation. |
function | repeating const | Returns true if the runner is in repeating mode. |
function | setRepeating | Enables or disables repeating mode. When repeating, the target function is invoked repeatedly until [cancel()](icy-Runner.html#cancel-2) is called. This normalizes behaviour across thread-based and event-loop-based [Runner](icy-Runner.html#runner) implementations. Must be called before [start()](icy-Runner.html#start-3). |
function | async virtual const | Returns true if the implementation is thread-based. |
function | tid const | Returns the native thread ID of the thread running the async context. |
function | waitForExit | Blocks until the async context exits or the timeout elapses. The context should be cancelled before calling this method. Must be called from outside the runner's own thread to avoid deadlock. |
variable | _context | Shared pointer to the internal Context. |
function | Runner | NonCopyable and NonMovable. |
function | operator= | Deleted assignment operator. |
function | Runner | Deleted constructor. |
function | operator= | Deleted assignment operator. |
Public Methods
| 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 override | 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
Synchronizer(uv::Loop * loop)Defined in src/base/include/icy/synchronizer.h:46
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).
Parameters
loopEvent loop to attach the async handle to.
Synchronizer
Synchronizer(std::function< void()> target, uv::Loop * loop = uv::defaultLoop())Defined in src/base/include/icy/synchronizer.h:52
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.
Parameters
targetCallback to invoke on each event loop wakeup.loopEvent loop to attach the async handle to.
Synchronizer
inline explicit
template<typename Function, typename... Args> inline explicit Synchronizer(Function && func, Args &&... args, uv::Loop * loop = uv::defaultLoop())Defined in src/base/include/icy/synchronizer.h:61
Creates and immediately starts a synchronizer with a variadic callback.
Parameters
FunctionCallable type.ArgsArgument types forwarded to the function.
Parameters
funcCallable to invoke on each event loop wakeup.argsArguments forwarded tofunc.loopEvent loop to attach the async handle to.
~Synchronizer
virtual
virtual ~Synchronizer()Defined in src/base/include/icy/synchronizer.h:69
Destructor.
post
void post()Defined in src/base/include/icy/synchronizer.h:75
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.
start
inline
template<typename Function, typename... Args> inline void start(Function && func, Args &&... args)Defined in src/base/include/icy/synchronizer.h:85
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.
Parameters
FunctionCallable type.ArgsArgument types forwarded to the function.
Parameters
funcCallable to invoke on each event loop wakeup.argsArguments forwarded tofunc.
start
virtual override
virtual void start(std::function< void()> func) overrideDefined in src/base/include/icy/synchronizer.h:131
Starts the synchronizer with a std::function callback. Overrides [Runner::start](icy-Runner.html#start-3); delegates to the variadic start template.
Parameters
funcCallback invoked from the event loop on each[post()](#post)call.
Reimplements
cancel
virtual
virtual void cancel()Defined in src/base/include/icy/synchronizer.h:135
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.
close
virtual
virtual void close()Defined in src/base/include/icy/synchronizer.h:139
Cancels the synchronizer and closes the underlying uv_async_t handle. Safe to call multiple times; no-op if already closed.
handle
uv::Handle< uv_async_t > & handle()Defined in src/base/include/icy/synchronizer.h:143
Returns a reference to the underlying libuv async handle.
Returns
Reference to the [uv::Handle](icy-uv-Handle.html#handle-6)<uv_async_t>.
Protected Attributes
| Return | Name | Description |
|---|---|---|
uv::Handle< uv_async_t > | _handle |
_handle
uv::Handle< uv_async_t > _handleDefined in src/base/include/icy/synchronizer.h:148
Protected Methods
| Return | Name | Description |
|---|---|---|
bool | async virtual const override | Returns true if the implementation is thread-based. |
async
virtual const override
virtual bool async() const overrideDefined in src/base/include/icy/synchronizer.h:146
Returns true if the implementation is thread-based.
Returns
True for thread-backed runners, false for event-loop-driven runners.
