diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-06-26 10:57:58 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-06-26 10:57:58 +0200 |
commit | 8e7a15754a3fef09cc5de372f207936740459c56 (patch) | |
tree | f1c3cc289eebc9ed9b620696b24467680288cc39 /src/OrderedQueue.h | |
parent | 899dcb83ec873cb35d38583d6f48922e1312e9be (diff) | |
download | ODR-SourceCompanion-8e7a15754a3fef09cc5de372f207936740459c56.tar.gz ODR-SourceCompanion-8e7a15754a3fef09cc5de372f207936740459c56.tar.bz2 ODR-SourceCompanion-8e7a15754a3fef09cc5de372f207936740459c56.zip |
Refactor OrderedQueue a bit
Diffstat (limited to 'src/OrderedQueue.h')
-rw-r--r-- | src/OrderedQueue.h | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/OrderedQueue.h b/src/OrderedQueue.h index c8958cb..4652762 100644 --- a/src/OrderedQueue.h +++ b/src/OrderedQueue.h @@ -25,23 +25,31 @@ #include <cstdint> #include <cstdio> +/* An queue that receives indexed frames, potentially out-of-order, + * which returns the frames in-order. + */ class OrderedQueue { public: - OrderedQueue(int32_t countModulo, size_t capacity); + /* Indexes of frames must be between 0 and maxIndex. + * The queue will fill to capacity if there is a gap. + */ + OrderedQueue(int32_t maxIndex, size_t capacity); - void push(int32_t count, const uint8_t* buf, size_t size); + void push(int32_t index, const uint8_t* buf, size_t size); bool availableData() const; - size_t pop(std::vector<uint8_t>& buf, int32_t *retCount=nullptr); + + /* Return the next buffer, or an empty buffer if none available */ + std::vector<uint8_t> pop(int32_t *retCount=nullptr); using OrderedQueueData = std::vector<uint8_t>; private: - int32_t _countModulo; + int32_t _maxIndex; size_t _capacity; uint64_t _duplicated = 0; uint64_t _overruns = 0; - int32_t _lastCount = -1; + int32_t _lastIndexPop = -1; std::map<int, OrderedQueueData> _stock; }; |