|
CIRCT 23.0.0git
|
Multi-producer / single-consumer dirty-set of channel ids, with CV-style blocking drain semantics. More...
#include <Utils.h>


Public Member Functions | |
| void | markReady (ID id) |
Add id to the dirty set and wake the consumer (if any). | |
| bool | waitDrain (std::unordered_set< ID > &out, std::optional< std::chrono::milliseconds > backoff={}) |
Block until either requestShutdown() is called or the set is non-empty, then atomically swap the current set into out. | |
| void | requestShutdown () |
Signal a clean shutdown: wakes every current and future waitDrain caller, which will then observe false. | |
| bool | isShutdown () const |
True once requestShutdown() has been called. | |
Private Attributes | |
| std::mutex | mutex |
| std::condition_variable | cv |
| std::unordered_set< ID > | ready |
| bool | shutdown = false |
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.
|
inline |
True once requestShutdown() has been called.
Definition at line 219 of file Utils.h.
References esi::utils::ReadyIdSet< ID >::mutex, and esi::utils::ReadyIdSet< ID >::shutdown.
Referenced by esi::cosim::RpcServer::Impl::transportLoop().
|
inline |
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 esi::utils::ReadyIdSet< ID >::cv, esi::utils::ReadyIdSet< ID >::mutex, and esi::utils::ReadyIdSet< ID >::ready.
Referenced by esi::cosim::RpcServer::Impl::handleSubscribe().
|
inline |
Signal a clean shutdown: wakes every current and future waitDrain caller, which will then observe false.
Idempotent.
Definition at line 210 of file Utils.h.
References esi::utils::ReadyIdSet< ID >::cv, esi::utils::ReadyIdSet< ID >::mutex, and esi::utils::ReadyIdSet< ID >::shutdown.
Referenced by esi::cosim::RpcServer::Impl::stop().
|
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.
Referenced by esi::cosim::RpcServer::Impl::transportLoop().
|
private |
Definition at line 226 of file Utils.h.
Referenced by esi::utils::ReadyIdSet< ID >::markReady(), and esi::utils::ReadyIdSet< ID >::requestShutdown().
|
mutableprivate |
Definition at line 225 of file Utils.h.
Referenced by esi::utils::ReadyIdSet< ID >::isShutdown(), esi::utils::ReadyIdSet< ID >::markReady(), and esi::utils::ReadyIdSet< ID >::requestShutdown().
|
private |
Definition at line 227 of file Utils.h.
Referenced by esi::utils::ReadyIdSet< ID >::markReady().
|
private |
Definition at line 228 of file Utils.h.
Referenced by esi::utils::ReadyIdSet< ID >::isShutdown(), and esi::utils::ReadyIdSet< ID >::requestShutdown().