Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::ipc::MpscConsumer Class Reference

Multi-producer single-consumer - consumer side. More...

#include <mpsc_shm.hpp>

Public Member Functions

 MpscConsumer (MpscConsumer &&other) noexcept
 
MpscConsumeroperator= (MpscConsumer &&other) noexcept
 
 MpscConsumer (const MpscConsumer &)=delete
 
MpscConsumeroperator= (const MpscConsumer &)=delete
 
 ~MpscConsumer ()
 
int wait_for_data (uint32_t timeout_ns)
 Wait for data on any ring.
 
void * peek (size_t ring_idx, size_t want, uint32_t timeout_ns)
 Peek data from specific ring.
 
void release (size_t ring_idx, size_t n)
 Release data from specific ring.
 
void wakeup_all ()
 Wake all blocked threads (for graceful shutdown) Wakes consumer blocked on doorbell and all producers blocked on their rings.
 

Static Public Member Functions

static MpscConsumer create (const std::string &name, size_t num_producers, size_t ring_capacity)
 Create MPSC consumer.
 
static bool unlink (const std::string &name, size_t num_producers)
 Unlink all shared memory for this MPSC system.
 

Private Member Functions

 MpscConsumer (std::vector< SpscShm > &&rings, int doorbell_fd, size_t doorbell_len, MpscDoorbell *doorbell)
 

Private Attributes

std::vector< SpscShmrings_
 
int doorbell_fd_ = -1
 
size_t doorbell_len_ = 0
 
MpscDoorbelldoorbell_ = nullptr
 
size_t last_served_ = 0
 
bool previous_had_data_ = false
 

Detailed Description

Multi-producer single-consumer - consumer side.

Manages multiple SPSC rings (one per producer) and waits on a shared doorbell.

Definition at line 41 of file mpsc_shm.hpp.

Constructor & Destructor Documentation

◆ MpscConsumer() [1/3]

bb::ipc::MpscConsumer::MpscConsumer ( MpscConsumer &&  other)
noexcept

Definition at line 28 of file mpsc_shm.cpp.

◆ MpscConsumer() [2/3]

bb::ipc::MpscConsumer::MpscConsumer ( const MpscConsumer )
delete

◆ ~MpscConsumer()

bb::ipc::MpscConsumer::~MpscConsumer ( )

Definition at line 68 of file mpsc_shm.cpp.

◆ MpscConsumer() [3/3]

bb::ipc::MpscConsumer::MpscConsumer ( std::vector< SpscShm > &&  rings,
int  doorbell_fd,
size_t  doorbell_len,
MpscDoorbell doorbell 
)
private

Definition at line 21 of file mpsc_shm.cpp.

Member Function Documentation

◆ create()

MpscConsumer bb::ipc::MpscConsumer::create ( const std::string &  name,
size_t  num_producers,
size_t  ring_capacity 
)
static

Create MPSC consumer.

Parameters
nameBase name for shared memory objects
num_producersNumber of producer rings to create
ring_capacityCapacity for each SPSC ring
Exceptions
std::runtime_errorif creation fails

Definition at line 78 of file mpsc_shm.cpp.

◆ operator=() [1/2]

MpscConsumer & bb::ipc::MpscConsumer::operator= ( const MpscConsumer )
delete

◆ operator=() [2/2]

MpscConsumer & bb::ipc::MpscConsumer::operator= ( MpscConsumer &&  other)
noexcept

Definition at line 41 of file mpsc_shm.cpp.

◆ peek()

void * bb::ipc::MpscConsumer::peek ( size_t  ring_idx,
size_t  want,
uint32_t  timeout_ns 
)

Peek data from specific ring.

Parameters
ring_idxRing index
wantMinimum bytes required
timeout_nsTimeout in nanoseconds
Returns
Pointer to data, or nullptr on timeout

Definition at line 246 of file mpsc_shm.cpp.

◆ release()

void bb::ipc::MpscConsumer::release ( size_t  ring_idx,
size_t  n 
)

Release data from specific ring.

Parameters
ring_idxRing index
nBytes to release

Definition at line 254 of file mpsc_shm.cpp.

◆ unlink()

bool bb::ipc::MpscConsumer::unlink ( const std::string &  name,
size_t  num_producers 
)
static

Unlink all shared memory for this MPSC system.

Parameters
nameBase name
num_producersNumber of producers
Returns
true if all unlinks successful

Definition at line 138 of file mpsc_shm.cpp.

◆ wait_for_data()

int bb::ipc::MpscConsumer::wait_for_data ( uint32_t  timeout_ns)

Wait for data on any ring.

Parameters
timeout_nsTotal timeout in nanoseconds (spins 10ms, then futex waits for remainder)
Returns
Ring index with data, or -1 on timeout

Definition at line 151 of file mpsc_shm.cpp.

◆ wakeup_all()

void bb::ipc::MpscConsumer::wakeup_all ( )

Wake all blocked threads (for graceful shutdown) Wakes consumer blocked on doorbell and all producers blocked on their rings.

Definition at line 261 of file mpsc_shm.cpp.

Member Data Documentation

◆ doorbell_

MpscDoorbell* bb::ipc::MpscConsumer::doorbell_ = nullptr
private

Definition at line 103 of file mpsc_shm.hpp.

◆ doorbell_fd_

int bb::ipc::MpscConsumer::doorbell_fd_ = -1
private

Definition at line 101 of file mpsc_shm.hpp.

◆ doorbell_len_

size_t bb::ipc::MpscConsumer::doorbell_len_ = 0
private

Definition at line 102 of file mpsc_shm.hpp.

◆ last_served_

size_t bb::ipc::MpscConsumer::last_served_ = 0
private

Definition at line 104 of file mpsc_shm.hpp.

◆ previous_had_data_

bool bb::ipc::MpscConsumer::previous_had_data_ = false
private

Definition at line 105 of file mpsc_shm.hpp.

◆ rings_

std::vector<SpscShm> bb::ipc::MpscConsumer::rings_
private

Definition at line 100 of file mpsc_shm.hpp.


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