12 #ifndef SST_CORE_INTERPROCESS_CIRCULARBUFFER_H
13 #define SST_CORE_INTERPROCESS_CIRCULARBUFFER_H
19 namespace Interprocess {
31 void setBufferSize(
const size_t bufferSize)
33 if ( buffSize != 0 ) {
34 fprintf(stderr,
"Already specified size for buffer\n");
38 buffSize = bufferSize;
48 if( readIndex != writeIndex ) {
49 const T result = buffer[readIndex];
50 readIndex = (readIndex + 1) % buffSize;
57 bufferMutex.processorPause(loop_counter++);
61 bool readNB(T* result) {
62 if( bufferMutex.try_lock() ) {
63 if( readIndex != writeIndex ) {
64 *result = buffer[readIndex];
65 readIndex = (readIndex + 1) % buffSize;
77 void write(
const T& v) {
83 if( ((writeIndex + 1) % buffSize) != readIndex ) {
84 buffer[writeIndex] = v;
85 writeIndex = (writeIndex + 1) % buffSize;
93 bufferMutex.processorPause(loop_counter++);
103 readIndex = writeIndex;
104 __sync_synchronize();
105 bufferMutex.unlock();
Definition: circularBuffer.h:22
Definition: sstmutex.h:25