X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iotcloud.git;a=blobdiff_plain;f=version2%2Fsrc%2FC%2FSlotBuffer.cc;h=248abd78017f03237e0f74cd8cf5bfc8403ad962;hp=4ddf4ba3c7b0c4d12c3ac519f7a12b4118d487d4;hb=816ad1a5d417a8710281974df64ab97e3369360f;hpb=0b9aca2b62c74f68652b170a92271a98d5b96666 diff --git a/version2/src/C/SlotBuffer.cc b/version2/src/C/SlotBuffer.cc index 4ddf4ba..248abd7 100644 --- a/version2/src/C/SlotBuffer.cc +++ b/version2/src/C/SlotBuffer.cc @@ -1,4 +1,5 @@ #include "SlotBuffer.h" +#include "Slot.h" /** * Circular buffer that holds the live set of slots. * @author Brian Demsky @@ -12,6 +13,10 @@ SlotBuffer::SlotBuffer() : oldestseqn(0) { } +SlotBuffer::~SlotBuffer() { + delete array; +} + int SlotBuffer::size() { if (head >= tail) return head - tail; @@ -55,7 +60,6 @@ void SlotBuffer::putSlot(Slot *s) { int64_t checkNum = (getNewestSeqNum() + 1); if (checkNum != s->getSequenceNumber()) { - // We have a gap so expunge all our slots oldestseqn = s->getSequenceNumber(); tail = 0; head = 1; @@ -76,12 +80,11 @@ void SlotBuffer::putSlot(Slot *s) { } } -Slot SlotBuffer::getSlot(int64_t seqnum) { +Slot *SlotBuffer::getSlot(int64_t seqnum) { int32_t diff = (int32_t) (seqnum - oldestseqn); int32_t index = diff + tail; if (index < 0) { - // Really old message so we dont have it anymore return NULL; } @@ -92,10 +95,10 @@ Slot SlotBuffer::getSlot(int64_t seqnum) { index -= array->length(); } - if (index >= array->length) { - + if (index >= array->length()) { return NULL; } + if (head >= tail && index >= head) { return NULL; }