File tree Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ static int FileWriteStr(const std::string &str, FILE *fp)
41
41
42
42
bool BCLog::Logger::StartLogging ()
43
43
{
44
- std::lock_guard<std::mutex> scoped_lock (m_file_mutex );
44
+ std::lock_guard<std::mutex> scoped_lock (m_cs );
45
45
46
46
assert (m_buffering);
47
47
assert (m_fileout == nullptr );
@@ -216,9 +216,9 @@ std::string BCLog::Logger::LogTimestampStr(const std::string& str)
216
216
return strStamped;
217
217
}
218
218
219
- void BCLog::Logger::LogPrintStr (const std::string & str)
219
+ void BCLog::Logger::LogPrintStr (const std::string& str)
220
220
{
221
- std::lock_guard<std::mutex> scoped_lock (m_file_mutex );
221
+ std::lock_guard<std::mutex> scoped_lock (m_cs );
222
222
std::string str_prefixed = str;
223
223
224
224
if (m_log_threadnames && m_started_new_line) {
Original file line number Diff line number Diff line change @@ -60,10 +60,10 @@ namespace BCLog {
60
60
class Logger
61
61
{
62
62
private:
63
- FILE* m_fileout = nullptr ;
64
- std::mutex m_file_mutex;
65
- std::list<std::string> m_msgs_before_open;
66
- bool m_buffering = true ; // !< Buffer messages before logging can be started
63
+ 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
64
+ FILE* m_fileout = nullptr ; // GUARDED_BY(m_cs)
65
+ std::list<std::string> m_msgs_before_open; // GUARDED_BY(m_cs)
66
+ bool m_buffering{ true }; // !< Buffer messages before logging can be started. GUARDED_BY(m_cs)
67
67
68
68
/* *
69
69
* m_started_new_line is a state variable that will suppress printing of
@@ -89,10 +89,14 @@ namespace BCLog {
89
89
std::atomic<bool > m_reopen_file{false };
90
90
91
91
/* * Send a string to the log output */
92
- void LogPrintStr (const std::string & str);
92
+ void LogPrintStr (const std::string& str);
93
93
94
94
/* * Returns whether logs will be written to any output */
95
- bool Enabled () const { return m_buffering || m_print_to_console || m_print_to_file; }
95
+ bool Enabled () const
96
+ {
97
+ std::lock_guard<std::mutex> scoped_lock (m_cs);
98
+ return m_buffering || m_print_to_console || m_print_to_file;
99
+ }
96
100
97
101
/* * Start logging (and flush all buffered messages) */
98
102
bool StartLogging ();
You can’t perform that action at this time.
0 commit comments