COROIO: NNet::TNotifier< TPoller > Class Template Reference
COROIO
Loading...
Searching...
No Matches
NNet::TNotifier< TPoller > Class Template Referencefinal

Thread-safe notification with a single asynchronous listener. More...

#include <notifier.hpp>

Inheritance diagram for NNet::TNotifier< TPoller >:
NNet::INotifier

Public Member Functions

 TNotifier (TPoller &poller)
 Creates a notifier bound to the listener's event-loop poller.
 TNotifier (const TNotifier &)=delete
TNotifier & operator= (const TNotifier &)=delete
void Notify () override
 Signals the listener from any thread.
TFuture< void > Wait () override
 Asynchronously waits for and consumes a notification.

Detailed Description

template<typename TPoller>
class NNet::TNotifier< TPoller >

Thread-safe notification with a single asynchronous listener.

Producers call Notify() from any thread after publishing work. Calls coalesce until Wait() consumes the signal; a notification means "check for work", not one work item. Wait() re-arms the notifier before returning to the listener.

TNotifier notifier(loop.Poller());
// Producer thread: publish work, then signal the listener.
notifier.Notify();
// Event-loop coroutine: wait, then drain available work.
co_await notifier.Wait();
TNotifier(TPoller &poller)
Creates a notifier bound to the listener's event-loop poller.
Definition notifier.hpp:95

Code that must not depend on the poller type holds an INotifier&.

Template Parameters
TPollerThe poller type of the listener's event loop; deduced from the constructor argument.
Note
Linux uses eventfd; other POSIX platforms use a non-blocking pipe. Works with every POSIX poller: epoll, kqueue, poll, select, and uring.
The poller must outlive the notifier. Stop producers and destroy or complete all waits before destroying the notifier.

Member Function Documentation

◆ Notify()

template<typename TPoller>
void NNet::TNotifier< TPoller >::Notify ( )
inlineoverridevirtual

Signals the listener from any thread.

Only the first call writes to the wakeup descriptor until the listener consumes the signal. A notification sent before Wait() is retained.

Implements NNet::INotifier.

◆ Wait()

template<typename TPoller>
TFuture< void > NNet::TNotifier< TPoller >::Wait ( )
inlineoverridevirtual

Asynchronously waits for and consumes a notification.

Call on the poller thread, with at most one outstanding wait. The caller must check all available work after waking because notifications coalesce. Destroying an unfinished future cancels its wait on the poller thread.

Exceptions
std::logic_errorif another wait is already outstanding.

Implements NNet::INotifier.


The documentation for this class was generated from the following file: