diff options
author | MarcoFalke <falke.marco@gmail.com> | 2019-05-28 10:39:29 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2019-05-28 14:27:08 -0400 |
commit | faa2a47cd7bcdbd187035c76f8dbd0442f6818dc (patch) | |
tree | 55d94c93f37e77734e8c0b50ccd6c9419fc59dc2 /src/logging.h | |
parent | 0b282f9b00da08734e2381477aad32d64b933745 (diff) |
logging: Add threadsafety comments
Diffstat (limited to 'src/logging.h')
-rw-r--r-- | src/logging.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/logging.h b/src/logging.h index f40a10bc4c..36b1a4045d 100644 --- a/src/logging.h +++ b/src/logging.h @@ -60,10 +60,10 @@ namespace BCLog { class Logger { private: - FILE* m_fileout = nullptr; - std::mutex m_file_mutex; - std::list<std::string> m_msgs_before_open; - bool m_buffering = true; //!< Buffer messages before logging can be started + 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 + FILE* m_fileout = nullptr; // GUARDED_BY(m_cs) + std::list<std::string> m_msgs_before_open; // GUARDED_BY(m_cs) + bool m_buffering{true}; //!< Buffer messages before logging can be started. GUARDED_BY(m_cs) /** * m_started_new_line is a state variable that will suppress printing of @@ -89,10 +89,14 @@ namespace BCLog { std::atomic<bool> m_reopen_file{false}; /** Send a string to the log output */ - void LogPrintStr(const std::string &str); + void LogPrintStr(const std::string& str); /** Returns whether logs will be written to any output */ - bool Enabled() const { return m_buffering || m_print_to_console || m_print_to_file; } + bool Enabled() const + { + std::lock_guard<std::mutex> scoped_lock(m_cs); + return m_buffering || m_print_to_console || m_print_to_file; + } /** Start logging (and flush all buffered messages) */ bool StartLogging(); |