lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
psalg::shmem::TransitionCache Class Reference

Tracks the transition buffers in shared memory: a stack of buffers holding the cached transitions of the current state, a list of free buffers, and a per-buffer bitmask of clients still using each buffer. More...

#include <TransitionCache.hh>

Public Member Functions

 TransitionCache (char *p, size_t sz, unsigned)
 Use the third argument as the number of buffers, each sz bytes, starting at p; write a Reset transition Dgram into each and mark all of them free with no clients.
 
 ~TransitionCache ()
 Destroy the semaphore and free the per-buffer client masks.
 
void dump () const
 Print each buffer's transition name, time and client mask, then the cached and free buffer indexes, to stdout.
 
std::stack< int > current ()
 Return the cached buffer indexes as a stack whose top is the oldest cached transition (the reverse of the internal order).
 
int allocate (XtcData::TransitionId::Value)
 Choose the first free buffer that no client holds for transition id and update the cache: Configure starts it, the next begin transition (top id + 2) is pushed, the matching end (top id + 1) pops the top, Disable pops entries above BeginStep, and up to three SlowUpdates are counted.
 
bool allocate (int ibuffer, unsigned client)
 Add client to the client mask of buffer ibuffer and return true.
 
bool deallocate (int ibuffer, unsigned client)
 Remove client from the mask of buffer ibuffer (printing a message if it was not set); when a SlowUpdate buffer becomes unused the SlowUpdate count is decremented.
 
void deallocate (unsigned client)
 Retire client: clear its bit in the not-ready mask and in every buffer's client mask.
 
unsigned not_ready () const
 Return the bitmask of clients marked not ready (per the member comment, clients that are behind in processing).
 

Detailed Description

Tracks the transition buffers in shared memory: a stack of buffers holding the cached transitions of the current state, a list of free buffers, and a per-buffer bitmask of clients still using each buffer.

Per the header comment, it caches transitions for clients and tracks those still to be served to late clients. A process-local semaphore guards the state.

Constructor & Destructor Documentation

◆ TransitionCache()

psalg::shmem::TransitionCache::TransitionCache ( char *  p,
size_t  sz,
unsigned   
)

Use the third argument as the number of buffers, each sz bytes, starting at p; write a Reset transition Dgram into each and mark all of them free with no clients.

◆ ~TransitionCache()

psalg::shmem::TransitionCache::~TransitionCache ( )

Destroy the semaphore and free the per-buffer client masks.

Member Function Documentation

◆ allocate() [1/2]

bool psalg::shmem::TransitionCache::allocate ( int  ibuffer,
unsigned  client 
)

Add client to the client mask of buffer ibuffer and return true.

If client is marked not ready, this is refused (returns false) unless the buffer holds a SlowUpdate or an end transition (odd id) lower than every end transition the client already holds.

◆ allocate() [2/2]

int psalg::shmem::TransitionCache::allocate ( XtcData::TransitionId::Value  )

Choose the first free buffer that no client holds for transition id and update the cache: Configure starts it, the next begin transition (top id + 2) is pushed, the matching end (top id + 1) pops the top, Disable pops entries above BeginStep, and up to three SlowUpdates are counted.

Other transitions are reported on stderr and rolled back, or abort() is called if a begin transition was skipped. For begin (even) ids, clients still holding an Enable buffer are added to the not-ready mask.

Returns
The buffer index, or -1 if no buffer is free.

◆ current()

std::stack< int > psalg::shmem::TransitionCache::current ( )

Return the cached buffer indexes as a stack whose top is the oldest cached transition (the reverse of the internal order).

◆ deallocate() [1/2]

bool psalg::shmem::TransitionCache::deallocate ( int  ibuffer,
unsigned  client 
)

Remove client from the mask of buffer ibuffer (printing a message if it was not set); when a SlowUpdate buffer becomes unused the SlowUpdate count is decremented.

Returns
true if client was marked not ready and now holds no buffer, in which case its not-ready bit is cleared; otherwise false.

◆ deallocate() [2/2]

void psalg::shmem::TransitionCache::deallocate ( unsigned  client)

Retire client: clear its bit in the not-ready mask and in every buffer's client mask.

◆ dump()

void psalg::shmem::TransitionCache::dump ( ) const

Print each buffer's transition name, time and client mask, then the cached and free buffer indexes, to stdout.

◆ not_ready()

unsigned psalg::shmem::TransitionCache::not_ready ( ) const
inline

Return the bitmask of clients marked not ready (per the member comment, clients that are behind in processing).


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