ITCH 5.0 Market Data Handler 1.0.0
NASDAQ ITCH 5.0 Market Data Feed Handler
Loading...
Searching...
No Matches
b2bits::Event< Auto > Struct Template Reference

Generic synchronization event. More...

Detailed Description

template<bool Auto>
struct b2bits::Event< Auto >

Generic synchronization event.

A thread synchronization primitive that allows threads to signal and wait for events. The event can be in either signaled or non-signaled state.

Behavior depends on the Auto template parameter:

  • Auto = true: Auto-reset event - automatically resets to non-signaled after waking one waiting thread (useful for one-shot notifications)
  • Auto = false: Manual-reset event - remains signaled until explicitly reset, waking all waiting threads (useful for broadcast notifications)

The event provides:

  • set(): Signal the event (wake waiting threads)
  • reset(): Clear the signal (manual-reset events only)
  • wait(): Block until signaled, with optional timeout
Template Parameters
AutoIf true, event auto-resets after waking one thread; if false, event stays signaled until manual reset
Note
Thread-safe: All operations are internally synchronized
Uses standard library condition_variable for efficient blocking
Example:
// Auto-reset event (wakes one thread, then resets)
AutoEvent ready;
// Producer thread
process_data();
ready.set(); // Wake one consumer
// Consumer thread
if (ready.wait(1000)) { // Wait up to 1 second
consume_data();
}
// Manual-reset event (wakes all threads, stays signaled)
ManualEvent shutdown;
// Main thread
shutdown.set(); // Wake all workers
// Worker threads
while (!shutdown.wait(0)) { // Check without blocking
do_work();
}
Event< true > AutoEvent
Auto-reset event type alias.
Definition Event.h:230
Event< false > ManualEvent
Manual-reset event type alias.
Definition Event.h:243
bool wait(D duration=D(typename D::rep(-1)))
Wait for event with duration-based timeout.
Definition Event.h:148
void set()
Set event to signaled state.
Definition Event.h:114

#include <core/src/Event.h>

Public Member Functions

 Event (bool signaled=false)
 Construct an event.
void reset ()
 Reset event to non-signaled state.
void set ()
 Set event to signaled state.
template<typename D>
bool wait (D duration=D(typename D::rep(-1)))
 Wait for event with duration-based timeout.
bool wait (unsigned ms=unsigned(-1))
 Wait for event with millisecond timeout.

Constructor & Destructor Documentation

◆ Event()

template<bool Auto>
b2bits::Event< Auto >::Event ( bool signaled = false)
inline

Construct an event.

Creates an event in either signaled or non-signaled state.

Parameters
signaledInitial state (default: false = non-signaled)

Member Function Documentation

◆ reset()

template<bool Auto>
void b2bits::Event< Auto >::reset ( )
inline

Reset event to non-signaled state.

For manual-reset events, this must be called explicitly to clear the signal. For auto-reset events, this happens automatically but can be called to force a reset.

Note
Thread-safe

◆ set()

template<bool Auto>
void b2bits::Event< Auto >::set ( )
inline

Set event to signaled state.

Signals the event, waking waiting threads:

  • Auto-reset: Wakes one waiting thread, then auto-resets
  • Manual-reset: Wakes all waiting threads, stays signaled

If no threads are waiting, the event remains signaled until a thread calls wait() or reset() is called.

Note
Thread-safe

◆ wait() [1/2]

template<bool Auto>
template<typename D>
bool b2bits::Event< Auto >::wait ( D duration = D(typename D::rep(-1)))
inline

Wait for event with duration-based timeout.

Blocks the calling thread until the event is signaled or the specified duration elapses. Supports any std::chrono::duration type.

Template Parameters
DDuration type (e.g., std::chrono::seconds, std::chrono::milliseconds)
Parameters
durationMaximum time to wait (default: infinite = -1)
Returns
true if event was signaled, false if timeout occurred
Note
Auto-reset: First waiter consumes the signal (event resets)
Manual-reset: All waiters wake (event stays signaled)
Thread-safe
Example:
using namespace std::chrono_literals;
if (event.wait(500ms)) {
// Event signaled within 500ms
} else {
// Timeout
}

Referenced by b2bits::Event< true >::wait().

◆ wait() [2/2]

template<bool Auto>
bool b2bits::Event< Auto >::wait ( unsigned ms = unsigned(-1))
inline

Wait for event with millisecond timeout.

Blocks the calling thread until the event is signaled or the specified timeout (in milliseconds) elapses.

The implementation handles spurious wakeups by re-checking the signaled state and adjusting the remaining timeout accordingly.

Parameters
msTimeout in milliseconds (default: infinite = -1)
Returns
true if event was signaled, false if timeout occurred
Note
Auto-reset: First waiter consumes the signal (event resets)
Manual-reset: All waiters wake (event stays signaled)
Thread-safe
Handles spurious wakeups correctly
Example:
// Wait indefinitely
event.wait();
// Wait 1 second
if (event.wait(1000)) {
// Signaled
}
// Check without blocking
if (event.wait(0)) {
// Already signaled
}

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