-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathqueue.h
executable file
·58 lines (50 loc) · 1007 Bytes
/
queue.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
#ifndef QUEUE_H
#define QUEUE_H
#include "definitions.h"
#include <mutex>
#include <condition_variable>
#include <vector>
#include <deque>
#include <iostream>
// all that we need to send to node/pool
struct MinerShare
{
MinerShare();
MinerShare(uint64_t _nonce)
{
nonce = _nonce;
}
uint64_t nonce;
};
//simple blocking queue for solutions sending
template<class T> class BlockQueue
{
std::deque<T> cont;
std::mutex mut;
std::condition_variable condv;
public:
void put(T &val)
{
mut.lock();
cont.push_front(val);
mut.unlock();
condv.notify_one();
}
void put(T &&val)
{
mut.lock();
cont.push_front(val);
mut.unlock();
condv.notify_one();
}
T get()
{
std::unique_lock<std::mutex> lock(mut);
condv.wait(lock, [=]{
return !cont.empty(); });
T tmp = cont.back();
cont.pop_back();
return tmp;
}
};
#endif