mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-07 06:09:42 +00:00
flush log only when queue is empty
This commit is contained in:
8
Queue.h
8
Queue.h
@@ -5,6 +5,7 @@
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
@@ -104,6 +105,8 @@ namespace util
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::function<void()> OnEmpty;
|
||||
|
||||
MsgQueue (): m_IsRunning (true), m_Thread (std::bind (&MsgQueue<Msg>::Run, this)) {};
|
||||
void Stop()
|
||||
{
|
||||
@@ -112,6 +115,8 @@ namespace util
|
||||
m_Thread.join();
|
||||
}
|
||||
|
||||
void SetOnEmpty (OnEmpty const & e) { m_OnEmpty = e; };
|
||||
|
||||
private:
|
||||
|
||||
void Run ()
|
||||
@@ -123,6 +128,8 @@ namespace util
|
||||
msg->Process ();
|
||||
delete msg;
|
||||
}
|
||||
if (m_OnEmpty != nullptr)
|
||||
m_OnEmpty ();
|
||||
Queue<Msg>::Wait ();
|
||||
}
|
||||
}
|
||||
@@ -131,6 +138,7 @@ namespace util
|
||||
|
||||
bool m_IsRunning;
|
||||
std::thread m_Thread;
|
||||
OnEmpty m_OnEmpty;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user