mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
flush log only when queue is empty
This commit is contained in:
parent
42f228e75a
commit
58939de57e
3 changed files with 31 additions and 6 deletions
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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue