mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 08:14:15 +00:00
Rewrite the thread stop in Queue
This commit is contained in:
parent
1c1103dcce
commit
9897a49e1a
8
Queue.h
8
Queue.h
@ -98,17 +98,18 @@ namespace util
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MsgQueue (): m_Thread (std::bind (&MsgQueue<Msg>::Run, this)) {};
|
MsgQueue (): m_Thread (std::bind (&MsgQueue<Msg>::Run, this)) , running(1) {};
|
||||||
void Stop()
|
void Stop()
|
||||||
{
|
{
|
||||||
m_Thread.detach();
|
running = 0;
|
||||||
|
m_Thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Run ()
|
void Run ()
|
||||||
{
|
{
|
||||||
Msg * msg = nullptr;
|
Msg * msg = nullptr;
|
||||||
while ((msg = Queue<Msg>::GetNext ()) != nullptr)
|
while ((msg = Queue<Msg>::GetNext ()) != nullptr && running)
|
||||||
{
|
{
|
||||||
msg->Process ();
|
msg->Process ();
|
||||||
delete msg;
|
delete msg;
|
||||||
@ -117,6 +118,7 @@ namespace util
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::thread m_Thread;
|
std::thread m_Thread;
|
||||||
|
int running;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user