Belle II Software light-2406-ragdoll
|
Class to manage a Ring Buffer placed in an IPC shared memory. More...
#include <RingBuffer.h>
Public Member Functions | |
RingBuffer (int nwords=c_DefaultSize) | |
Constructor to create a new shared memory in private space. | |
RingBuffer (const std::string &name, unsigned int nwords=0) | |
Constructor to create/attach named shared memory in global space. | |
~RingBuffer () | |
Destructor. | |
void | openSHM (int nwords) |
open shared memory | |
void | cleanup () |
Function to detach and remove shared memory. | |
int | insq (const int *buf, int size, bool checkTx=false) |
Append a buffer to the RingBuffer. | |
int | remq (int *buf) |
Pick up a buffer from the RingBuffer. | |
int | spyq (int *buf) const |
Prefetch a buffer from the RingBuffer w/o removing it. | |
int | numq () const |
Returns number of entries/buffers in the RingBuffer. | |
void | txAttached () |
Increase the number of attached Tx counter. | |
void | txDetached () |
Decrease the number of attached Tx counter. | |
void | kill () |
Cause termination of reading processes (if they use isDead()). | |
bool | isDead () const |
If True, the ring buffer is empty and has no attached Tx modules (i.e. | |
bool | allRxWaiting () const |
True if and only if buffer is empty and nbusy == 0. | |
int | clear () |
Clear the RingBuffer. | |
void | forceClear () |
Forcefully clear the RingBuffer with resetting semaphore. | |
int | tryClear () |
Clear the RingBuffer, if the semaphore isn't locked at the moment. | |
int | shmid () const |
Return ID of the shared memory. | |
void | dump_db () |
Print some info on the RingBufInfo structure. | |
int | ninsq () const |
Return number of insq() calls for current buffer. | |
int | nremq () const |
Return number of remq() calls for current buffer. | |
int | insq_counter () const |
Return number of insq() calls. | |
int | remq_counter () const |
Return number of remq() calls. | |
void | dumpInfo () const |
Dump contents of RingBufInfo metadata. | |
Static Public Attributes | |
static const int | c_DefaultSize = 15000000 |
Standard size of buffer, in integers (~60MB). | |
Private Attributes | |
bool | m_new {true} |
True if we created the ring buffer ourselves (and need to clean it). | |
bool | m_file {false} |
True if m_pathfd needs to be closed. | |
std::string | m_pathname {""} |
Path for identifying shared memory if named ring buffer is created. | |
int | m_pathfd { -1} |
Associated file descriptor. | |
key_t | m_shmkey {IPC_PRIVATE} |
SHM key, see shmget(2). | |
key_t | m_semkey {IPC_PRIVATE} |
Semaphore key, see semget(2). | |
std::string | m_semshmFileName {""} |
file path containing ids of shm and sema for private shared mem, used for easier cleanup if we fail to do things properly | |
bool | m_procIsBusy {false} |
Is this process currently processing events from this RingBuffer? | |
int | m_shmid { -1} |
ID of shared memory segment. | |
int * | m_shmadr {nullptr} |
Address of attached shared memory segment. | |
int | m_shmsize { -1} |
Size of shared memory segment, in bytes. | |
struct RingBufInfo * | m_bufinfo {nullptr} |
structure to manage ring buffer. | |
int * | m_buftop {nullptr} |
Points to memory after the end of m_bufinfo. | |
int | m_semid { -1} |
Semaphore ID. | |
int | m_remq_counter {0} |
count remq() calls. | |
int | m_insq_counter {0} |
count insq() calls. | |
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition at line 39 of file RingBuffer.h.
|
explicit |
Constructor to create a new shared memory in private space.
nwords | Ring buffer size in integers |
Definition at line 32 of file RingBuffer.cc.
|
explicit |
Constructor to create/attach named shared memory in global space.
Definition at line 39 of file RingBuffer.cc.
~RingBuffer | ( | ) |
Destructor.
Definition at line 79 of file RingBuffer.cc.
bool allRxWaiting | ( | ) | const |
True if and only if buffer is empty and nbusy == 0.
Called in Tx to see if all events of the current run have been processed
Definition at line 400 of file RingBuffer.cc.
void cleanup | ( | ) |
Function to detach and remove shared memory.
Definition at line 162 of file RingBuffer.cc.
int clear | ( | ) |
Clear the RingBuffer.
Definition at line 426 of file RingBuffer.cc.
void dump_db | ( | ) |
void dumpInfo | ( | ) | const |
Dump contents of RingBufInfo metadata.
Definition at line 463 of file RingBuffer.cc.
void forceClear | ( | ) |
Forcefully clear the RingBuffer with resetting semaphore.
Definition at line 441 of file RingBuffer.cc.
int insq | ( | const int * | buf, |
int | size, | ||
bool | checkTx = false |
||
) |
Append a buffer to the RingBuffer.
Definition at line 189 of file RingBuffer.cc.
int insq_counter | ( | ) | const |
Return number of insq() calls.
Definition at line 416 of file RingBuffer.cc.
bool isDead | ( | ) | const |
If True, the ring buffer is empty and has no attached Tx modules (i.e.
no new data is going to be added). Processes should then stop.
Definition at line 394 of file RingBuffer.cc.
void kill | ( | ) |
Cause termination of reading processes (if they use isDead()).
Assumed to be atomic.
Definition at line 389 of file RingBuffer.cc.
int ninsq | ( | ) | const |
Return number of insq() calls for current buffer.
Definition at line 406 of file RingBuffer.cc.
int nremq | ( | ) | const |
Return number of remq() calls for current buffer.
Definition at line 411 of file RingBuffer.cc.
int numq | ( | ) | const |
Returns number of entries/buffers in the RingBuffer.
Definition at line 368 of file RingBuffer.cc.
void openSHM | ( | int | nwords | ) |
open shared memory
Definition at line 84 of file RingBuffer.cc.
int remq | ( | int * | buf | ) |
Pick up a buffer from the RingBuffer.
Definition at line 308 of file RingBuffer.cc.
int remq_counter | ( | ) | const |
Return number of remq() calls.
Definition at line 421 of file RingBuffer.cc.
int shmid | ( | ) | const |
Return ID of the shared memory.
Definition at line 458 of file RingBuffer.cc.
int spyq | ( | int * | buf | ) | const |
Prefetch a buffer from the RingBuffer w/o removing it.
Definition at line 348 of file RingBuffer.cc.
int tryClear | ( | ) |
Clear the RingBuffer, if the semaphore isn't locked at the moment.
See SemaphoreLocker::isLocked() for details
Definition at line 450 of file RingBuffer.cc.
void txAttached | ( | ) |
Increase the number of attached Tx counter.
Definition at line 373 of file RingBuffer.cc.
void txDetached | ( | ) |
Decrease the number of attached Tx counter.
Definition at line 381 of file RingBuffer.cc.
|
static |
Standard size of buffer, in integers (~60MB).
Needs to be large enough to contain any event, but adds to total memory use of basf2.
Definition at line 42 of file RingBuffer.h.
|
private |
structure to manage ring buffer.
Placed on top of the shared memory.
Definition at line 129 of file RingBuffer.h.
|
private |
Points to memory after the end of m_bufinfo.
Definition at line 130 of file RingBuffer.h.
|
private |
True if m_pathfd needs to be closed.
Definition at line 111 of file RingBuffer.h.
|
private |
count insq() calls.
Definition at line 133 of file RingBuffer.h.
|
private |
True if we created the ring buffer ourselves (and need to clean it).
Definition at line 110 of file RingBuffer.h.
|
private |
Associated file descriptor.
Definition at line 113 of file RingBuffer.h.
|
private |
Path for identifying shared memory if named ring buffer is created.
Definition at line 112 of file RingBuffer.h.
|
private |
Is this process currently processing events from this RingBuffer?
set during remq() with value depending on wether data was returned. Always false for a process that is only using insq().
Definition at line 124 of file RingBuffer.h.
|
private |
count remq() calls.
Definition at line 132 of file RingBuffer.h.
|
private |
Semaphore ID.
Definition at line 131 of file RingBuffer.h.
|
private |
Semaphore key, see semget(2).
Definition at line 115 of file RingBuffer.h.
|
private |
file path containing ids of shm and sema for private shared mem, used for easier cleanup if we fail to do things properly
Definition at line 117 of file RingBuffer.h.
|
private |
Address of attached shared memory segment.
(See shmat(2))
Definition at line 127 of file RingBuffer.h.
|
private |
|
private |
SHM key, see shmget(2).
Definition at line 114 of file RingBuffer.h.
|
private |
Size of shared memory segment, in bytes.
Definition at line 128 of file RingBuffer.h.