mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
* drop MsgQueue wrapper : not used anymore
This commit is contained in:
parent
c57b13d922
commit
3eae716a2d
46
Queue.h
46
Queue.h
@ -117,52 +117,6 @@ namespace util
|
||||
std::mutex m_QueueMutex;
|
||||
std::condition_variable m_NonEmpty;
|
||||
};
|
||||
|
||||
template<class Msg>
|
||||
class MsgQueue: public Queue<Msg *>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::function<void()> OnEmpty;
|
||||
|
||||
MsgQueue (): m_IsRunning (true), m_Thread (std::bind (&MsgQueue<Msg>::Run, this)) {};
|
||||
~MsgQueue () { Stop (); };
|
||||
void Stop()
|
||||
{
|
||||
if (m_IsRunning)
|
||||
{
|
||||
m_IsRunning = false;
|
||||
Queue<Msg *>::WakeUp ();
|
||||
m_Thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
void SetOnEmpty (OnEmpty const & e) { m_OnEmpty = e; };
|
||||
|
||||
private:
|
||||
|
||||
void Run ()
|
||||
{
|
||||
while (m_IsRunning)
|
||||
{
|
||||
while (auto msg = Queue<Msg *>::Get ())
|
||||
{
|
||||
msg->Process ();
|
||||
delete msg;
|
||||
}
|
||||
if (m_OnEmpty != nullptr)
|
||||
m_OnEmpty ();
|
||||
if (m_IsRunning)
|
||||
Queue<Msg *>::Wait ();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
volatile bool m_IsRunning;
|
||||
OnEmpty m_OnEmpty;
|
||||
std::thread m_Thread;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user