-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBlockingQueue.h
More file actions
39 lines (31 loc) · 861 Bytes
/
BlockingQueue.h
File metadata and controls
39 lines (31 loc) · 861 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
32
33
34
35
36
37
38
39
#ifndef __BLOCKING_QUEUE_H__
#define __BLOCKING_QUEUE_H__
#include <queue>
#include <mutex>
#include <thread>
#include <iostream>
using std::string;
template<typename T>
class BlockingQueue {
public:
explicit BlockingQueue();
void push(const T& t);
// This logs a message if the thread needs to be blocked.
// Useful for detecting if the data feeding is slow.
T pop(const string& log_on_wait = "");
bool try_peek(T* t);
bool try_pop(T* t);
// Return element without removing it
T peek();
size_t size() const;
protected:
class sync;
std::queue<T> queue_;
std::shared_ptr<sync> sync_;
private:
// disable copy constructor
BlockingQueue(const BlockingQueue&);
// disable assignment
BlockingQueue& operator=(const BlockingQueue&);
};
#endif // __BLOCKING_QUEUE_H__