Last change
on this file since 17976 was 16779, checked in by tbretz, 12 years ago |
A less CPU hungry version of the msg queue using C++11 techniques.
|
File size:
1.0 KB
|
Line | |
---|
1 | #ifndef COSY_MsgQueue
|
---|
2 | #define COSY_MsgQueue
|
---|
3 |
|
---|
4 | #ifndef __CINT__
|
---|
5 | #include <list>
|
---|
6 | #include <mutex>
|
---|
7 | #include <thread>
|
---|
8 | #include <vector>
|
---|
9 | #include <condition_variable>
|
---|
10 | #endif
|
---|
11 |
|
---|
12 | #define WM_NULL 0x0000
|
---|
13 | #define WM_QUIT 0xffff
|
---|
14 |
|
---|
15 | class MsgQueue
|
---|
16 | {
|
---|
17 | private:
|
---|
18 | size_t fSize; // Only necessary for before C++11
|
---|
19 |
|
---|
20 | #ifndef __CINT__
|
---|
21 | std::list<std::pair<int, std::vector<char>>> fList;
|
---|
22 |
|
---|
23 | std::mutex fMutex; // Mutex needed for the conditional
|
---|
24 | std::condition_variable fCond; // Conditional
|
---|
25 | #endif
|
---|
26 |
|
---|
27 | enum state_t
|
---|
28 | {
|
---|
29 | kIdle,
|
---|
30 | kRun,
|
---|
31 | kStop,
|
---|
32 | kAbort,
|
---|
33 | };
|
---|
34 |
|
---|
35 | state_t fState; // Stop signal for the thread
|
---|
36 | #ifndef __CINT__
|
---|
37 | std::thread fThread; // Handle to the thread
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | void Thread();
|
---|
41 |
|
---|
42 | public:
|
---|
43 | MsgQueue();
|
---|
44 | virtual ~MsgQueue();
|
---|
45 |
|
---|
46 | int Break() const;
|
---|
47 |
|
---|
48 | void CancelThread();
|
---|
49 |
|
---|
50 | virtual int Proc(int msg, void *mp1);
|
---|
51 | int Proc(int msg) { return Proc(msg, 0); }
|
---|
52 |
|
---|
53 | void *PostMsg(int msg, void *mp1, int size);
|
---|
54 | void *PostMsg(int msg) { return PostMsg(msg, 0, 0); }
|
---|
55 | };
|
---|
56 |
|
---|
57 | #endif
|
---|
Note:
See
TracBrowser
for help on using the repository browser.