2#ifndef DSY_RINGBUFFER_H
3#define DSY_RINGBUFFER_H
17template <
typename T,
size_t size>
24 inline void Init() { read_ptr_ = write_ptr_ = 0; }
32 return (read_ptr_ - write_ptr_ - 1) %
size;
36 inline size_t readable()
const {
return (write_ptr_ - read_ptr_) %
size; }
39 inline bool isEmpty()
const {
return write_ptr_ == read_ptr_; }
56 size_t w = write_ptr_;
58 write_ptr_ = (
w + 1) %
size;
78 read_ptr_ = (
r + 1) %
size;
83 inline void Flush() { write_ptr_ = read_ptr_; }
94 read_ptr_ = (write_ptr_ + 1 +
n) %
size;
103 size_t r = read_ptr_;
125 size_t w = write_ptr_;
148 if(write_ptr_ >
size)
149 write_ptr_ = write_ptr_ -
size;
158 volatile size_t read_ptr_;
159 volatile size_t write_ptr_;
180 inline T
Read() {
return T(0); }
Definition leddriver.h:33
void Init()
Definition ringbuffer.h:171
T ImmediateRead()
Definition ringbuffer.h:181
size_t capacity() const
Definition ringbuffer.h:172
T Read()
Definition ringbuffer.h:180
RingBuffer()
Definition ringbuffer.h:169
void Overwrite(const T *source, size_t num_elements)
Definition ringbuffer.h:188
void Write(T v)
Definition ringbuffer.h:175
size_t writable() const
Definition ringbuffer.h:173
void Flush()
Definition ringbuffer.h:182
void ImmediateRead(T *destination, size_t num_elements)
Definition ringbuffer.h:183
size_t readable() const
Definition ringbuffer.h:174
void Overwrite(T v)
Definition ringbuffer.h:176
Definition ringbuffer.h:19
T ImmediateRead()
Definition ringbuffer.h:74
T Read()
Definition ringbuffer.h:64
size_t writable() const
Definition ringbuffer.h:30
void Overwrite(const T *source, size_t num_elements)
Definition ringbuffer.h:123
bool isEmpty() const
Definition ringbuffer.h:39
void Init()
Definition ringbuffer.h:24
void Overwrite(T v)
Definition ringbuffer.h:54
T * GetMutableBuffer()
Definition ringbuffer.h:154
void Flush()
Definition ringbuffer.h:83
size_t readable() const
Definition ringbuffer.h:36
void Write(T v)
Definition ringbuffer.h:44
RingBuffer()
Definition ringbuffer.h:21
void Swallow(size_t n)
Definition ringbuffer.h:88
void ImmediateRead(T *destination, size_t num_elements)
Definition ringbuffer.h:101
void Advance(size_t num_elements)
Definition ringbuffer.h:142
size_t capacity() const
Definition ringbuffer.h:27
Hardware defines and helpers for daisy field platform.
Definition index.h:2