diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 10c704b2b..150109dbc 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -154,6 +154,7 @@ typedef struct { int ymax; /**< is the roi ymax (in channel number)*/ } ROI ; + /* /\* */ /* @short structure for a generic integer array */ /* *\/ */ diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer index 4edbb70d8..93bbce12b 100755 Binary files a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer and b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer differ diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h index 83f9d621e..f8438b75a 100644 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h @@ -10,6 +10,8 @@ + + /* #include #include diff --git a/slsDetectorSoftware/slsReceiver/circularFifo.h b/slsDetectorSoftware/slsReceiver/circularFifo.h index 154c89117..3c4c05670 100644 --- a/slsDetectorSoftware/slsReceiver/circularFifo.h +++ b/slsDetectorSoftware/slsReceiver/circularFifo.h @@ -3,11 +3,11 @@ * Do with source-code as you will. No requirement to keep this * header if need to use it/change it/ or do whatever with it * -* Note that there is No guarantee that this code will work +* Note that there is No guarantee that this code will work * and I take no responsibility for this code and any problems you * might get if using it. The code is highly platform dependent! * -* Code & platform dependent issues with it was originally +* Code & platform dependent issues with it was originally * published at http://www.kjellkod.cc/threadsafecircularqueue * 2009-11-02 * @author Kjell Hedstr�m, hedstrom@kjellkod.cc */ @@ -20,7 +20,7 @@ #include using namespace std; -/** Circular Fifo (a.k.a. Circular Buffer) +/** Circular Fifo (a.k.a. Circular Buffer) * Thread safe for one reader, and one writer */ template class CircularFifo { @@ -34,10 +34,10 @@ public: bool push(Element*& item_); bool pop(Element*& item_); - + bool isEmpty() const; bool isFull() const; - + private: volatile unsigned int tail; // input index vector array; @@ -50,7 +50,7 @@ private: -/** Producer only: Adds item to the circular queue. +/** Producer only: Adds item to the circular queue. * If queue is full at 'push' operation no update/overwrite * will happen, it is up to the caller to handle this case * @@ -124,10 +124,118 @@ unsigned int CircularFifo::increment(unsigned int idx_) const // index++; // if(index == array.lenght) -> index = 0; // - //or as written below: + //or as written below: // index = (index+1) % array.length idx_ = (idx_+1) % Capacity; return idx_; } #endif /* CIRCULARFIFO_H_ */ + + + + + +/* +#ifndef CIRCULARFIFO_H_ +#define CIRCULARFIFO_H_ + +#include "sls_detector_defs.h" + +#include "/usr/include/alsa/atomic.h" +#include +using namespace std; + +template +class CircularFifo { +public: + + CircularFifo(unsigned int Size) : tail(0), head(0){ + Capacity = Size + 1; + array.resize(Capacity); + } + virtual ~CircularFifo() {} + + bool push(Element*& item_); + bool pop(Element*& item_); + + bool wasEmpty() const; + bool wasFull() const; + bool isLockFree() const; + +private: + vector array; + unsigned int Capacity; + + std::atomic tail; // input index + std::atomic head; // output index + + unsigned int increment(unsigned int idx_) const; +}; + + +template +bool CircularFifo::push(Element*& item_) +{ + auto currentTail = tail.load(); + auto nextTail = increment(currentTail); + if(nextTail != head.load()) + { + array[currentTail] = item_; + tail.store(nextTail); + return true; + } + + // queue was full + return false; +} + + +template +bool CircularFifo::pop(Element*& item_) +{ + const auto currentHead = head.load(); + if(currentHead == tail.load()) + return false; // empty queue + + item_ = array[currentHead]; + head.store(increment(currentHead)); + return true; +} + + +template +bool CircularFifo::wasEmpty() const +{ + return (head.load() == tail.load()); +} + + +template +bool CircularFifo::wasFull() const +{ + const auto nextTail = increment(tail.load()); + return (nextTail == head.load()); +} + +template +bool CircularFifo::isLockFree() const +{ + return (tail.is_lock_free() && head.is_lock_free()); +} + + +template +unsigned int CircularFifo::increment(unsigned int idx_) const +{ + // increment or wrap + // ================= + // index++; + // if(index == array.lenght) -> index = 0; + // + //or as written below: + // index = (index+1) % array.length + return (idx_ + 1) % Capacity; +} + +#endif */