Multi-producer / single-consumer dirty-set of channel ids, with CV-style blocking drain semantics.
More...
template<typename ID = uint16_t>
class esi::utils::ReadyIdSet< ID >
Multi-producer / single-consumer dirty-set of channel ids, with CV-style blocking drain semantics.
Producers call markReady(id); the consumer thread calls waitDrain() to atomically swap out the current set.
Use this when many independent per-channel producers feed a single transport thread that needs to know which channels have work to do without polling each in turn. The CV pattern (lock-around-shutdown-set, notify-after-release, predicate captures both shutdown and !empty) is fiddly enough that centralising it here avoids subtle copy/paste bugs in each backend.
Definition at line 177 of file Utils.h.
template<typename ID = uint16_t>
Add id to the dirty set and wake the consumer (if any).
Idempotent w.r.t. an id that is already in the set.
Definition at line 181 of file Utils.h.
References cv, mutex, and ready.
template<typename ID = uint16_t>
| bool esi::utils::ReadyIdSet< ID >::waitDrain |
( |
std::unordered_set< ID > & | out, |
|
|
std::optional< std::chrono::milliseconds > | backoff = {} ) |
|
inline |
Block until either requestShutdown() is called or the set is non-empty, then atomically swap the current set into out.
With backoff non-nullopt, returns after the timeout even if neither condition holds (useful when the caller maintains its own retry set it wants to re-process periodically). Returns false once shutdown has been signalled, so consumer loops can write while (set.waitDrain(ids, backoff)) { ... }.
Definition at line 196 of file Utils.h.