|
|
|
@ -46,6 +46,12 @@ namespace util
@@ -46,6 +46,12 @@ namespace util
|
|
|
|
|
return el; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Wait () |
|
|
|
|
{ |
|
|
|
|
std::unique_lock<std::mutex> l(m_QueueMutex); |
|
|
|
|
m_NonEmpty.wait (l); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Wait (int sec, int usec) |
|
|
|
|
{ |
|
|
|
|
std::unique_lock<std::mutex> l(m_QueueMutex); |
|
|
|
@ -98,27 +104,33 @@ namespace util
@@ -98,27 +104,33 @@ namespace util
|
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
MsgQueue (): m_Thread (std::bind (&MsgQueue<Msg>::Run, this)) , running(1) {}; |
|
|
|
|
MsgQueue (): m_IsRunning (true), m_Thread (std::bind (&MsgQueue<Msg>::Run, this)) {}; |
|
|
|
|
void Stop() |
|
|
|
|
{ |
|
|
|
|
running = 0; |
|
|
|
|
m_IsRunning = false; |
|
|
|
|
Queue<Msg>::WakeUp (); |
|
|
|
|
m_Thread.join(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
void Run () |
|
|
|
|
{ |
|
|
|
|
Msg * msg = nullptr; |
|
|
|
|
while ((msg = Queue<Msg>::GetNext ()) != nullptr && running) |
|
|
|
|
while (m_IsRunning) |
|
|
|
|
{ |
|
|
|
|
while (Msg * msg = Queue<Msg>::Get ()) |
|
|
|
|
{ |
|
|
|
|
msg->Process (); |
|
|
|
|
delete msg; |
|
|
|
|
} |
|
|
|
|
Queue<Msg>::Wait (); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
bool m_IsRunning; |
|
|
|
|
std::thread m_Thread; |
|
|
|
|
volatile int running; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|