Loading...
Searching...
No Matches
meshkit::EventChannel Class Reference

Bounded, thread-safe event queue between one job and its consumer. More...

#include <meshkit/events.hpp>

Collaboration diagram for meshkit::EventChannel:

Classes

struct  Batch
 Events removed by one drain(). More...
 

Public Member Functions

 EventChannel (std::size_t capacity=2048)
 Create an empty channel with a new process-wide job id.
 
std::uint64_t job () const noexcept
 Id of this channel, unique among the channels created in the process.
 
void publish (Event event)
 Queue one event without waiting for the consumer.
 
Batch drain ()
 Remove and return every pending event.
 

Detailed Description

Bounded, thread-safe event queue between one job and its consumer.

Producers never wait for the consumer; publish() and drain() only hold an internal mutex, so they may be called from different threads. When the queue is full, the oldest pending Progress event (or, if there is none, the oldest event) is evicted and counted in Batch::dropped. After a Completed event, further events are ignored. The channel is neither copyable nor movable.

Constructor & Destructor Documentation

◆ EventChannel()

meshkit::EventChannel::EventChannel ( std::size_t capacity = 2048)
inlineexplicit

Create an empty channel with a new process-wide job id.

Parameters
[in]capacityMost pending events kept before eviction; values below 2 become 2. Default 2048.

Member Function Documentation

◆ drain()

Batch meshkit::EventChannel::drain ( )
inline

Remove and return every pending event.

Returns
The pending events, oldest first, and the cumulative dropped count (which drain() does not reset). Events are empty when nothing is pending.

◆ job()

std::uint64_t meshkit::EventChannel::job ( ) const
inlinenoexcept

Id of this channel, unique among the channels created in the process.

Returns
Job id, counted from 1.

◆ publish()

void meshkit::EventChannel::publish ( Event event)
inline

Queue one event without waiting for the consumer.

Cuts message, stage and code longer than 8192, 256 and 128 bytes back to a UTF-8 boundary within that size and appends "…" (the caller supplies UTF-8); stamps job, sequence and elapsedMs; and clamps a given percent (see Event::percent). A Progress event overwrites the newest pending event when that is a Progress event of the same stage. Does nothing after a Completed event has been published.

Parameters
[in]eventEvent to queue; taken by value and moved into the queue.
Here is the caller graph for this function:

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