-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogAsync.h
46 lines (35 loc) · 1.04 KB
/
LogAsync.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//---------------------------------------------------------------------------
#ifndef LogAsyncH
#define LogAsyncH
#include <queue>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <utility>
#include <atomic>
#include <functional>
#include "ILog.h"
namespace PitchDet {
class LogAsync : public ILog {
public:
using CallbackType = std::function<void(String,TColor)>;
LogAsync( CallbackType Callback );
LogAsync( LogAsync const & ) = delete;
LogAsync& operator=( LogAsync const & ) = delete;
~LogAsync();
protected:
virtual void DoLogMessage( String Text, TColor Color ) override;
virtual void DoClearLog() override {}
private:
using LogItemType = std::pair<String,TColor>;
CallbackType callback_;
std::atomic_bool stopped_;
std::queue<LogItemType> queue_;
std::mutex mutex_;
std::condition_variable condVar_;
std::thread thConsumer_;
void Run();
};
} // End of namespace RTTLogger
//---------------------------------------------------------------------------
#endif