A template for ring buffer implementation
Dependents: AwsomeStation LoRaBaseStation LoRaTerminal
Diff: RingBuffer.h
- Revision:
- 3:21ee07b29eb7
- Parent:
- 2:8949ad751081
- Child:
- 7:3e06927ef5ec
diff -r 8949ad751081 -r 21ee07b29eb7 RingBuffer.h --- a/RingBuffer.h Sat Jul 23 07:50:53 2016 +0000 +++ b/RingBuffer.h Thu Sep 01 04:01:40 2016 +0000 @@ -3,16 +3,17 @@ #define DEFAULT_MAX_BUFFER_SZ 64 -#include "stdint.h" +#include <stdint.h> +#include <stdlib.h> template <typename T> class CircularBuffer { private: - const uint32_t buffer_size; - uint32_t read_ptr; - uint32_t write_ptr; - uint32_t count; + const size_t buffer_size; + size_t read_ptr; + size_t write_ptr; + size_t count; // mutex lock bool mux; @@ -25,7 +26,7 @@ public: - CircularBuffer(const uint32_t size=DEFAULT_MAX_BUFFER_SZ); + CircularBuffer(const size_t size=DEFAULT_MAX_BUFFER_SZ); ~CircularBuffer(); // psudo mutex @@ -38,9 +39,9 @@ T dequeue(); // pointer operation - uint32_t getReadPtr(); - uint32_t getWritePtr(); - uint32_t getCounter(); + size_t getReadPtr(); + size_t getWritePtr(); + size_t getCounter(); // overflow bool getOverFlow(); @@ -51,7 +52,7 @@ T last(); // random access - T operator[](uint32_t idx); + T operator[](size_t idx); }; #endif \ No newline at end of file