diff --git a/src/libCom/ring/epicsRingPointer.h b/src/libCom/ring/epicsRingPointer.h index ff0254417..716ee33e7 100644 --- a/src/libCom/ring/epicsRingPointer.h +++ b/src/libCom/ring/epicsRingPointer.h @@ -12,16 +12,16 @@ of this distribution. #define INCepicsRingPointerh /* NOTES - If there is only one writer it is not necessary to lock push - If there is a single reader it is not necessary to lock pop -*/ + * If there is only one writer it is not necessary to lock push + * If there is a single reader it is not necessary to lock pop + */ #include "shareLib.h" #ifdef __cplusplus -template class epicsRingPointer -{ -public: +template +class epicsRingPointer { +public: // Functions epicsRingPointer(int size); ~epicsRingPointer(); bool push(T *p); @@ -32,20 +32,22 @@ public: int getSize() const; bool isEmpty() const; bool isFull() const; -private: + +private: // Prevent compiler-generated member functions + // default constructor, copy constructor, assignment operator + epicsRingPointer(); + epicsRingPointer(const epicsRingPointer &); + epicsRingPointer& operator=(const epicsRingPointer &); + +private: // Data int nextPush; int nextPop; int size; T **buffer; - // copy constructor and assignment operator not allowed - epicsRingPointer(const epicsRingPointer &); - epicsRingPointer& operator=(const epicsRingPointer &); }; -#endif /*__cplusplus */ -#ifdef __cplusplus extern "C" { -#endif +#endif /*__cplusplus */ typedef void *epicsRingPointerId; @@ -65,23 +67,28 @@ epicsShareFunc int epicsShareAPI epicsRingPointerIsFull(epicsRingPointerId id); #ifdef __cplusplus } #endif +/* END OF DECLARATIONS */ -/* Following is implementation */ +/* INLINE FUNCTIONS */ + /* Algorithm note -* Space is allocated for one additional element. -* A put request is rejected if the it would cause nextPush to equal nextPop -* The algorithm does not require locking puts for a single writer -* or locking of gets for a single reader -*/ + * Space is allocated for one additional element. + * A put request is rejected if the it would cause nextPush to equal nextPop + * The algorithm does not require locking puts for a single writer + * or locking of gets for a single reader + */ #ifdef __cplusplus -template inline epicsRingPointer::epicsRingPointer(int sz) -: nextPush(0), nextPop(0), size(sz+1), buffer(new T* [sz+1]) {} +template +inline epicsRingPointer::epicsRingPointer(int sz) : + nextPush(0), nextPop(0), size(sz+1), buffer(new T* [sz+1]) {} -template inline epicsRingPointer::~epicsRingPointer() -{delete [] buffer;} +template +inline epicsRingPointer::~epicsRingPointer() +{ delete [] buffer;} -template inline bool epicsRingPointer::push(T *p) +template +inline bool epicsRingPointer::push(T *p) { int newNext = nextPush +1; if(newNext>=size) newNext=0; @@ -91,7 +98,8 @@ template inline bool epicsRingPointer::push(T *p) return(true); } -template inline T* epicsRingPointer::pop() +template +inline T* epicsRingPointer::pop() { if(nextPop == nextPush) return(0); T*p = buffer[nextPop]; @@ -102,30 +110,36 @@ template inline T* epicsRingPointer::pop() return(p); } -template inline void epicsRingPointer::flush() -{ nextPop = nextPush = 0;} +template +inline void epicsRingPointer::flush() +{ nextPop = nextPush = 0;} -template inline int epicsRingPointer::getFree() const +template +inline int epicsRingPointer::getFree() const { int n = nextPop - nextPush - 1; if (n < 0) n += size; return n; } -template inline int epicsRingPointer::getUsed() const +template +inline int epicsRingPointer::getUsed() const { int n = nextPush - nextPop; if (n < 0) n += size; return n; } -template inline int epicsRingPointer::getSize() const -{return(size-1);} +template +inline int epicsRingPointer::getSize() const +{ return(size-1);} -template inline bool epicsRingPointer::isEmpty() const -{return(nextPush==nextPop);} +template +inline bool epicsRingPointer::isEmpty() const +{ return(nextPush==nextPop);} -template inline bool epicsRingPointer::isFull() const +template +inline bool epicsRingPointer::isFull() const { int count = nextPush - nextPop +1; return((count == 0) || (count == size));