-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathConcurrentQueue.h
More file actions
31 lines (26 loc) · 782 Bytes
/
ConcurrentQueue.h
File metadata and controls
31 lines (26 loc) · 782 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
#ifndef ConcurrentQueue_h
#define ConcurrentQueue_h
#include <CoreFoundation/CoreFoundation.h>
#include <vector>
#include <string>
#include <queue>
#include <mutex>
#include "Message.hpp"
namespace tns {
struct ConcurrentQueue {
public:
void Initialize(CFRunLoopRef runLoop, void (*performWork)(void*), void* info);
void Push(std::shared_ptr<worker::Message> message);
std::vector<std::shared_ptr<worker::Message>> PopAll();
void Terminate();
private:
std::queue<std::shared_ptr<worker::Message>> messagesQueue_;
CFRunLoopSourceRef runLoopTasksSource_ = nullptr;
CFRunLoopRef runLoop_ = nullptr;
bool terminated = false;
std::mutex mutex_;
std::mutex initializationMutex_;
void SignalAndWakeUp();
};
}
#endif /* ConcurrentQueue_h */