88
99#include < fs.h>
1010#include < tinyformat.h>
11+ #include < threadsafety.h>
1112#include < util/string.h>
1213
1314#include < atomic>
@@ -62,9 +63,10 @@ namespace BCLog {
6263 {
6364 private:
6465 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.
6870
6971 /* *
7072 * m_started_new_line is a state variable that will suppress printing of
@@ -79,7 +81,7 @@ namespace BCLog {
7981 std::string LogTimestampStr (const std::string& str);
8082
8183 /* * 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) {};
8385
8486 public:
8587 bool m_print_to_console = false ;
@@ -98,22 +100,22 @@ namespace BCLog {
98100 /* * Returns whether logs will be written to any output */
99101 bool Enabled () const
100102 {
101- std::lock_guard<std::mutex> scoped_lock (m_cs);
103+ LockGuard scoped_lock (m_cs);
102104 return m_buffering || m_print_to_console || m_print_to_file || !m_print_callbacks.empty ();
103105 }
104106
105107 /* * Connect a slot to the print signal and return the connection */
106108 std::list<std::function<void (const std::string&)>>::iterator PushBackCallback (std::function<void (const std::string&)> fun)
107109 {
108- std::lock_guard<std::mutex> scoped_lock (m_cs);
110+ LockGuard scoped_lock (m_cs);
109111 m_print_callbacks.push_back (std::move (fun));
110112 return --m_print_callbacks.end ();
111113 }
112114
113115 /* * Delete a connection */
114116 void DeleteCallback (std::list<std::function<void (const std::string&)>>::iterator it)
115117 {
116- std::lock_guard<std::mutex> scoped_lock (m_cs);
118+ LockGuard scoped_lock (m_cs);
117119 m_print_callbacks.erase (it);
118120 }
119121
0 commit comments