-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmutex.h
63 lines (52 loc) · 1.12 KB
/
cmutex.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
56
57
58
59
60
61
62
63
/*
* cmutex.h
*
* Created on 17 April 2014
* By: Synergiance
*/
#include <iostream>
#include <string>
#include <vector>
#include <thread>
#include <mutex>
#include <unistd.h>
#include <condition_variable>
#include <atomic>
using namespace std;
#ifndef CMUTEX_H_
#define CMUTEX_H_
struct CMutexMessage
{
public:
string command;
vector<string> command_arguments;
string str();
void clear();
};
class CMutex
{
public:
CMutex();
CMutex(bool debug);
// Access array -- Deprecating
void push(string str);
bool pull(string& str);
bool pull(string& str, int timeout);
bool pull(string& str, int timeout, int delay);
// Access array -- New
void push(CMutexMessage str);
bool pull(CMutexMessage& str);
bool pull(CMutexMessage& str, int timeout);
bool pull(CMutexMessage& str, int timeout, int delay);
private:
// Array
vector<CMutexMessage> strBuffer;
bool debugMode;
atomic_bool moreQuotes;
// Mutex
mutex mtx1, mtx2;
condition_variable cv;
// Blocked function
bool access(bool adding, CMutexMessage& msg);
};
#endif /* CMUTEX_H_ */