1 #ifndef GCP_UTIL_CIRCULARBUFFER_H
2 #define GCP_UTIL_CIRCULARBUFFER_H
14 #include "gcp/util/common/Mutex.h"
15 #include "gcp/util/common/Exception.h"
42 type*
getFrame(
unsigned int id,
bool create);
78 std::vector<struct CircularBufferSlot>
slots_;
95 std::map<unsigned int, struct CircularBufferSlot*> frameMap_;
116 unsigned long nUsed_;
157 ThrowError(
"nSlot < 1");
162 slots_.resize(nSlot_);
167 for(
unsigned islot=0; islot < nSlot_-1; islot++)
168 slots_[islot].next_ = &slots_[islot+1];
169 slots_[nSlot_-1].next_ = &slots_[0];
175 nextFreeSlot_ = &slots_[0];
176 nextSendSlot_ = &slots_[0];
199 type* dfm = nextSendSlot_->frame_;
204 frameMap_.erase(nextSendSlot_->id_);
214 if(lastSentSlot_ != 0) {
215 clearSlot(lastSentSlot_);
222 lastSentSlot_ = nextSendSlot_;
226 nextSendSlot_ = nextSendSlot_->next_;
239 struct CircularBufferSlot* slot = nextFreeSlot_;
245 clearSlot(nextSendSlot_);
246 nextSendSlot_ = nextSendSlot_->next_;
256 nextFreeSlot_ = nextFreeSlot_->next_;
315 if(slot != 0 || !create) {
319 frame = (slot == 0) ? 0 : slot->frame_;
324 slot = getNextSlot();
333 frameMap_[id] = slot;
341 frame = slot->frame_;
355 ThrowError(
"Caught an exception");
369 std::map<unsigned int, struct CircularBufferSlot*>::iterator slot;
371 slot = frameMap_.find(
id);
373 if(slot != frameMap_.end())
397 frameMap_.erase(slot->id_);
401 slot->frame_->unlock();
405 slot->frame_->reinitialize();
412 #endif // End #ifndef GCP_UTIL_CIRCULARBUFFER_H
type * getNextFrame()
Definition: CircularBuffer.h:265
type * dispatchNextFrame()
Definition: CircularBuffer.h:190
type * getFrame(unsigned int id, bool create)
Definition: CircularBuffer.h:284
unsigned int getNframesInQueue()
Definition: CircularBuffer.h:384
CircularBuffer(unsigned nFrame)
Definition: CircularBuffer.h:143
std::vector< struct CircularBufferSlot > slots_
Definition: CircularBuffer.h:78
Definition: CircularBuffer.h:69
virtual ~CircularBuffer()
Definition: CircularBuffer.h:183
unsigned long nSlot_
Definition: CircularBuffer.h:83
Definition: CircularBuffer.h:23