27 #ifndef INCepicsRingPointerh 28 #define INCepicsRingPointerh 32 #include "libComAPI.h" 41 class epicsRingPointer {
47 epicsRingPointer(
int size,
bool locked);
91 int getHighWaterMark()
const;
96 void resetHighWaterMark();
101 epicsRingPointer(
const epicsRingPointer &);
102 epicsRingPointer& operator=(
const epicsRingPointer &);
103 int getUsedNoLock()
const;
107 volatile int nextPush;
108 volatile int nextPop;
111 T *
volatile * buffer;
207 #define epicsRingPointerSize epicsRingPointerGetSize 219 inline epicsRingPointer<T>::epicsRingPointer(
int sz,
bool locked) :
220 lock(0), nextPush(0), nextPop(0), size(sz+1), highWaterMark(0),
221 buffer(new T* [sz+1])
228 inline epicsRingPointer<T>::~epicsRingPointer()
235 inline bool epicsRingPointer<T>::push(T *p)
239 int newNext = next + 1;
240 if(newNext>=size) newNext=0;
241 if (newNext == nextPop) {
247 int used = getUsedNoLock();
248 if (used > highWaterMark) highWaterMark = used;
254 inline T* epicsRingPointer<T>::pop()
258 if (next == nextPush) {
264 if(next >=size) next = 0;
280 inline int epicsRingPointer<T>::getFree()
const 283 int n = nextPop - nextPush - 1;
284 if (n < 0) n += size;
290 inline int epicsRingPointer<T>::getUsedNoLock()
const 292 int n = nextPush - nextPop;
293 if (n < 0) n += size;
298 inline int epicsRingPointer<T>::getUsed()
const 301 int n = getUsedNoLock();
307 inline int epicsRingPointer<T>::getSize()
const 313 inline bool epicsRingPointer<T>::isEmpty()
const 317 isEmpty = (nextPush == nextPop);
323 inline bool epicsRingPointer<T>::isFull()
const 326 int count = nextPush - nextPop +1;
328 return((count == 0) || (count == size));
332 inline int epicsRingPointer<T>::getHighWaterMark()
const 334 return highWaterMark;
338 inline void epicsRingPointer<T>::resetHighWaterMark()
341 highWaterMark = getUsedNoLock();
LIBCOM_API epicsRingPointerId epicsStdCall epicsRingPointerCreate(int size)
Create a new ring buffer.
LIBCOM_API void epicsStdCall epicsRingPointerResetHighWaterMark(epicsRingPointerId id)
Reset the Highwater mark of the ring buffer.
LIBCOM_API int epicsStdCall epicsRingPointerGetUsed(epicsRingPointerId id)
Return the number of elements stored in the ring buffer.
LIBCOM_API void epicsStdCall epicsRingPointerFlush(epicsRingPointerId id)
Remove all elements from the ring.
LIBCOM_API int epicsStdCall epicsRingPointerPush(epicsRingPointerId id, void *p)
Push pointer into the ring buffer.
LIBCOM_API void *epicsStdCall epicsRingPointerPop(epicsRingPointerId id)
Take an element off the ring.
LIBCOM_API int epicsStdCall epicsRingPointerGetHighWaterMark(epicsRingPointerIdConst id)
Get the Highwater mark of the ring buffer.
LIBCOM_API int epicsStdCall epicsRingPointerIsEmpty(epicsRingPointerId id)
Check if the ring buffer is currently empty.
LIBCOM_API void epicsStdCall epicsRingPointerDelete(epicsRingPointerId id)
Delete the ring buffer and free any associated memory.
LIBCOM_API int epicsStdCall epicsRingPointerIsFull(epicsRingPointerId id)
Check if the ring buffer is currently full.
LIBCOM_API int epicsStdCall epicsRingPointerGetFree(epicsRingPointerId id)
Return the amount of empty space in the ring buffer.
void const * epicsRingPointerIdConst
LIBCOM_API epicsRingPointerId epicsStdCall epicsRingPointerLockedCreate(int size)
Create a new ring buffer, secured by a spinlock.
void * epicsRingPointerId
An identifier for the C API to a ring buffer storing pointers.
LIBCOM_API void epicsSpinDestroy(epicsSpinId)
LIBCOM_API int epicsStdCall epicsRingPointerGetSize(epicsRingPointerId id)
Return the size of the ring.
LIBCOM_API void epicsSpinLock(epicsSpinId)
LIBCOM_API epicsSpinId epicsSpinCreate(void)
LIBCOM_API void epicsSpinUnlock(epicsSpinId)