8
8
9
9
#include < fs.h>
10
10
#include < tinyformat.h>
11
+ #include < threadsafety.h>
11
12
#include < util/string.h>
12
13
13
14
#include < atomic>
@@ -62,9 +63,10 @@ namespace BCLog {
62
63
{
63
64
private:
64
65
mutable std::mutex m_cs; // Can not use Mutex from sync.h because in debug mode it would cause a deadlock when a potential deadlock was detected
65
- FILE* m_fileout = nullptr ; // GUARDED_BY(m_cs)
66
- std::list<std::string> m_msgs_before_open; // GUARDED_BY(m_cs)
67
- bool m_buffering{true }; // !< Buffer messages before logging can be started. GUARDED_BY(m_cs)
66
+
67
+ FILE* m_fileout GUARDED_BY (m_cs) = nullptr;
68
+ std::list<std::string> m_msgs_before_open GUARDED_BY (m_cs);
69
+ bool m_buffering GUARDED_BY (m_cs) = true; // !< Buffer messages before logging can be started.
68
70
69
71
/* *
70
72
* m_started_new_line is a state variable that will suppress printing of
@@ -79,7 +81,7 @@ namespace BCLog {
79
81
std::string LogTimestampStr (const std::string& str);
80
82
81
83
/* * Slots that connect to the print signal */
82
- std::list<std::function<void (const std::string&)>> m_print_callbacks /* GUARDED_BY(m_cs) */ {};
84
+ std::list<std::function<void (const std::string&)>> m_print_callbacks GUARDED_BY (m_cs) {};
83
85
84
86
public:
85
87
bool m_print_to_console = false ;
@@ -98,22 +100,22 @@ namespace BCLog {
98
100
/* * Returns whether logs will be written to any output */
99
101
bool Enabled () const
100
102
{
101
- std::lock_guard<std::mutex> scoped_lock (m_cs);
103
+ LockGuard scoped_lock (m_cs);
102
104
return m_buffering || m_print_to_console || m_print_to_file || !m_print_callbacks.empty ();
103
105
}
104
106
105
107
/* * Connect a slot to the print signal and return the connection */
106
108
std::list<std::function<void (const std::string&)>>::iterator PushBackCallback (std::function<void (const std::string&)> fun)
107
109
{
108
- std::lock_guard<std::mutex> scoped_lock (m_cs);
110
+ LockGuard scoped_lock (m_cs);
109
111
m_print_callbacks.push_back (std::move (fun));
110
112
return --m_print_callbacks.end ();
111
113
}
112
114
113
115
/* * Delete a connection */
114
116
void DeleteCallback (std::list<std::function<void (const std::string&)>>::iterator it)
115
117
{
116
- std::lock_guard<std::mutex> scoped_lock (m_cs);
118
+ LockGuard scoped_lock (m_cs);
117
119
m_print_callbacks.erase (it);
118
120
}
119
121
0 commit comments