Skip to content

Commit cbc231e

Browse files
committed
scripted-diff: logging: Switch from StdLockGuard to STDLOCK
-BEGIN VERIFY SCRIPT- sed -i 's/StdLockGuard scoped_lock(\(.*\));/STDLOCK(\1);/' src/logging.h src/logging.cpp -END VERIFY SCRIPT-
1 parent f808786 commit cbc231e

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/logging.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int FileWriteStr(std::string_view str, FILE *fp)
5353

5454
bool BCLog::Logger::StartLogging()
5555
{
56-
StdLockGuard scoped_lock(m_cs);
56+
STDLOCK(m_cs);
5757

5858
assert(m_buffering);
5959
assert(m_fileout == nullptr);
@@ -97,7 +97,7 @@ bool BCLog::Logger::StartLogging()
9797

9898
void BCLog::Logger::DisconnectTestLogger()
9999
{
100-
StdLockGuard scoped_lock(m_cs);
100+
STDLOCK(m_cs);
101101
m_buffering = true;
102102
if (m_fileout != nullptr) fclose(m_fileout);
103103
m_fileout = nullptr;
@@ -111,7 +111,7 @@ void BCLog::Logger::DisconnectTestLogger()
111111
void BCLog::Logger::DisableLogging()
112112
{
113113
{
114-
StdLockGuard scoped_lock(m_cs);
114+
STDLOCK(m_cs);
115115
assert(m_buffering);
116116
assert(m_print_callbacks.empty());
117117
}
@@ -159,7 +159,7 @@ bool BCLog::Logger::WillLogCategoryLevel(BCLog::LogFlags category, BCLog::Level
159159

160160
if (!WillLogCategory(category)) return false;
161161

162-
StdLockGuard scoped_lock(m_cs);
162+
STDLOCK(m_cs);
163163
const auto it{m_category_log_levels.find(category)};
164164
return level >= (it == m_category_log_levels.end() ? LogLevel() : it->second);
165165
}
@@ -392,7 +392,7 @@ BCLog::LogRateLimiter::Status BCLog::LogRateLimiter::Consume(
392392
const SourceLocation& source_loc,
393393
const std::string& str)
394394
{
395-
StdLockGuard scoped_lock(m_mutex);
395+
STDLOCK(m_mutex);
396396
auto& stats{m_source_locations.try_emplace(source_loc, m_max_bytes).first->second};
397397
Status status{stats.m_dropped_bytes > 0 ? Status::STILL_SUPPRESSED : Status::UNSUPPRESSED};
398398

@@ -423,7 +423,7 @@ void BCLog::Logger::FormatLogStrInPlace(std::string& str, BCLog::LogFlags catego
423423

424424
void BCLog::Logger::LogPrintStr(std::string_view str, SourceLocation&& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit)
425425
{
426-
StdLockGuard scoped_lock(m_cs);
426+
STDLOCK(m_cs);
427427
return LogPrintStr_(str, std::move(source_loc), category, level, should_ratelimit);
428428
}
429429

@@ -556,7 +556,7 @@ void BCLog::LogRateLimiter::Reset()
556556
{
557557
decltype(m_source_locations) source_locations;
558558
{
559-
StdLockGuard scoped_lock(m_mutex);
559+
STDLOCK(m_mutex);
560560
source_locations.swap(m_source_locations);
561561
m_suppression_active = false;
562562
}
@@ -598,7 +598,7 @@ bool BCLog::Logger::SetCategoryLogLevel(std::string_view category_str, std::stri
598598
const auto level = GetLogLevel(level_str);
599599
if (!level.has_value() || level.value() > MAX_USER_SETABLE_SEVERITY_LEVEL) return false;
600600

601-
StdLockGuard scoped_lock(m_cs);
601+
STDLOCK(m_cs);
602602
m_category_log_levels[flag] = level.value();
603603
return true;
604604
}

src/logging.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,28 +192,28 @@ namespace BCLog {
192192
/** Returns whether logs will be written to any output */
193193
bool Enabled() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
194194
{
195-
StdLockGuard scoped_lock(m_cs);
195+
STDLOCK(m_cs);
196196
return m_buffering || m_print_to_console || m_print_to_file || !m_print_callbacks.empty();
197197
}
198198

199199
/** Connect a slot to the print signal and return the connection */
200200
std::list<std::function<void(const std::string&)>>::iterator PushBackCallback(std::function<void(const std::string&)> fun) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
201201
{
202-
StdLockGuard scoped_lock(m_cs);
202+
STDLOCK(m_cs);
203203
m_print_callbacks.push_back(std::move(fun));
204204
return --m_print_callbacks.end();
205205
}
206206

207207
/** Delete a connection */
208208
void DeleteCallback(std::list<std::function<void(const std::string&)>>::iterator it) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
209209
{
210-
StdLockGuard scoped_lock(m_cs);
210+
STDLOCK(m_cs);
211211
m_print_callbacks.erase(it);
212212
}
213213

214214
size_t NumConnections() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
215215
{
216-
StdLockGuard scoped_lock(m_cs);
216+
STDLOCK(m_cs);
217217
return m_print_callbacks.size();
218218
}
219219

@@ -224,7 +224,7 @@ namespace BCLog {
224224

225225
void SetRateLimiting(std::shared_ptr<LogRateLimiter> limiter) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
226226
{
227-
StdLockGuard scoped_lock(m_cs);
227+
STDLOCK(m_cs);
228228
m_limiter = std::move(limiter);
229229
}
230230

@@ -240,17 +240,17 @@ namespace BCLog {
240240

241241
std::unordered_map<LogFlags, Level> CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
242242
{
243-
StdLockGuard scoped_lock(m_cs);
243+
STDLOCK(m_cs);
244244
return m_category_log_levels;
245245
}
246246
void SetCategoryLogLevel(const std::unordered_map<LogFlags, Level>& levels) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
247247
{
248-
StdLockGuard scoped_lock(m_cs);
248+
STDLOCK(m_cs);
249249
m_category_log_levels = levels;
250250
}
251251
void AddCategoryLogLevel(LogFlags category, Level level) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
252252
{
253-
StdLockGuard scoped_lock(m_cs);
253+
STDLOCK(m_cs);
254254
m_category_log_levels[category] = level;
255255
}
256256
bool SetCategoryLogLevel(std::string_view category_str, std::string_view level_str) EXCLUSIVE_LOCKS_REQUIRED(!m_cs);

0 commit comments

Comments
 (0)