Skip to content

Commit 6bbc2dd

Browse files
committed
logging: Add thread safety annotations
1 parent 173ab0c commit 6bbc2dd

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/logging.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,48 +127,49 @@ namespace BCLog {
127127
std::string GetLogPrefix(LogFlags category, Level level) const;
128128

129129
/** Send a string to the log output */
130-
void LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, int source_line, BCLog::LogFlags category, BCLog::Level level);
130+
void LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, int source_line, BCLog::LogFlags category, BCLog::Level level)
131+
EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
131132

132133
/** Returns whether logs will be written to any output */
133-
bool Enabled() const
134+
bool Enabled() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
134135
{
135136
StdLockGuard scoped_lock(m_cs);
136137
return m_buffering || m_print_to_console || m_print_to_file || !m_print_callbacks.empty();
137138
}
138139

139140
/** Connect a slot to the print signal and return the connection */
140-
std::list<std::function<void(const std::string&)>>::iterator PushBackCallback(std::function<void(const std::string&)> fun)
141+
std::list<std::function<void(const std::string&)>>::iterator PushBackCallback(std::function<void(const std::string&)> fun) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
141142
{
142143
StdLockGuard scoped_lock(m_cs);
143144
m_print_callbacks.push_back(std::move(fun));
144145
return --m_print_callbacks.end();
145146
}
146147

147148
/** Delete a connection */
148-
void DeleteCallback(std::list<std::function<void(const std::string&)>>::iterator it)
149+
void DeleteCallback(std::list<std::function<void(const std::string&)>>::iterator it) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
149150
{
150151
StdLockGuard scoped_lock(m_cs);
151152
m_print_callbacks.erase(it);
152153
}
153154

154155
/** Start logging (and flush all buffered messages) */
155-
bool StartLogging();
156+
bool StartLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
156157
/** Only for testing */
157-
void DisconnectTestLogger();
158+
void DisconnectTestLogger() EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
158159

159160
void ShrinkDebugFile();
160161

161-
std::unordered_map<LogFlags, Level> CategoryLevels() const
162+
std::unordered_map<LogFlags, Level> CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
162163
{
163164
StdLockGuard scoped_lock(m_cs);
164165
return m_category_log_levels;
165166
}
166-
void SetCategoryLogLevel(const std::unordered_map<LogFlags, Level>& levels)
167+
void SetCategoryLogLevel(const std::unordered_map<LogFlags, Level>& levels) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
167168
{
168169
StdLockGuard scoped_lock(m_cs);
169170
m_category_log_levels = levels;
170171
}
171-
bool SetCategoryLogLevel(const std::string& category_str, const std::string& level_str);
172+
bool SetCategoryLogLevel(const std::string& category_str, const std::string& level_str) EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
172173

173174
Level LogLevel() const { return m_log_level.load(); }
174175
void SetLogLevel(Level level) { m_log_level = level; }
@@ -182,7 +183,7 @@ namespace BCLog {
182183
bool DisableCategory(const std::string& str);
183184

184185
bool WillLogCategory(LogFlags category) const;
185-
bool WillLogCategoryLevel(LogFlags category, Level level) const;
186+
bool WillLogCategoryLevel(LogFlags category, Level level) const EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
186187

187188
/** Returns a vector of the log categories in alphabetical order. */
188189
std::vector<LogCategory> LogCategoriesList() const;

0 commit comments

Comments
 (0)