Belle II Software
release-08-01-10
|
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. More... | |
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()). More... | |
bool | isDead () const |
If True, the ring buffer is empty and has no attached Tx modules (i.e. More... | |
bool | allRxWaiting () const |
True if and only if buffer is empty and nbusy == 0. More... | |
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. More... | |
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). More... | |
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? More... | |
int | m_shmid { -1} |
ID of shared memory segment. More... | |
int * | m_shmadr {nullptr} |
Address of attached shared memory segment. More... | |
int | m_shmsize { -1} |
Size of shared memory segment, in bytes. | |
struct RingBufInfo * | m_bufinfo {nullptr} |
structure to manage ring buffer. More... | |
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.
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.
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 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.
|
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 |
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 |
Address of attached shared memory segment.
(See shmat(2))
Definition at line 127 of file RingBuffer.h.
|
private |