-
Notifications
You must be signed in to change notification settings - Fork 0
/
ring.h
55 lines (43 loc) · 843 Bytes
/
ring.h
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
#include <mutex>
#include <atomic>
#include <condition_variable>
#include <iostream>
#include "..\..\std_lib_facilities.h"
template<class T>
class RingBuffer
{
public:
RingBuffer();
RingBuffer(int size);
~RingBuffer();
void put(T val);
T get();
void printindex();
/*
T tryGet();
T peek();
*/
bool notFull();
bool notEmpty();
//int size();
//int bufferSize();
//Ring& operator<<(T obj);
//Ring& operator<<(T& obj);
//
private:
void incWriteIndex();
void incReadIndex();
T* Buffer;
int NumOfElements = 0;
int BufferSize = 0;
int ReadIndex = 0;
int WriteIndex = 0;
mutex lock;
/*std::mutex mAccessMutex;
std::mutex mReadMutex;
std::mutex mWriteMutex;
std::mutex mNumberMutex;*/
condition_variable FullCv;
condition_variable EmptyCv;
};