COROIO: NNet::TNotifier Class Reference
COROIO
Loading...
Searching...
No Matches
NNet::TNotifier Class Reference

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

#include <notifier.hpp>

Public Member Functions

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

Detailed Description

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(poller);
// Producer thread: publish work, then signal the listener.
notifier.Notify();
// Event-loop coroutine: wait, then drain available work.
co_await notifier.Wait();
TNotifier(TPollerBase &poller)
Creates a notifier bound to the listener's event-loop poller.
Definition notifier.cpp:17
Note
Linux uses eventfd; other POSIX platforms use a non-blocking pipe. Supports readiness pollers: epoll, kqueue, poll, and select.
The poller must outlive the notifier. Stop producers and destroy or complete all waits before destroying the notifier.

Member Function Documentation

◆ Notify()

void NNet::TNotifier::Notify ( )

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.

◆ Wait()

TFuture< void > NNet::TNotifier::Wait ( )

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.

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