flush log only when queue is empty

This commit is contained in:
orignal 2014-04-23 12:49:02 -04:00
parent 42f228e75a
commit 58939de57e
3 changed files with 31 additions and 6 deletions

View file

@ -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;
};
}
}