-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathringbuffer.h
More file actions
32 lines (29 loc) · 802 Bytes
/
ringbuffer.h
File metadata and controls
32 lines (29 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* ringbuffer.h
*/
#include <atomic>
#include <string>
class RingBuffer
{
public:
RingBuffer(unsigned long size,std::string name);
~RingBuffer();
unsigned long push(float *data,unsigned long n);
unsigned long pop(float *data,unsigned long n);
unsigned long items_available_for_write();
unsigned long items_available_for_read();
bool isLockFree();
void pushMayBlock(bool block);
void popMayBlock(bool block);
void setBlockingNap(unsigned long blockingNap);
private:
unsigned long size;
float *buffer;
std::atomic<unsigned long> tail; // write pointer
std::atomic<unsigned long> head; // read pointer
unsigned long itemsize; // also depends on #channels
std::string name;
bool blockingPush;
bool blockingPop;
unsigned long blockingNap=500;
}; // RingBuffer{}