From cbc231ed8ee346dfd46384012b0028668bc899d3 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Thu, 12 Mar 2026 04:33:31 +1000 Subject: [PATCH] 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- --- src/logging.cpp | 16 ++++++++-------- src/logging.h | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/logging.cpp b/src/logging.cpp index df6946d6611..bfd48c96211 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -53,7 +53,7 @@ static int FileWriteStr(std::string_view str, FILE *fp) bool BCLog::Logger::StartLogging() { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); assert(m_buffering); assert(m_fileout == nullptr); @@ -97,7 +97,7 @@ bool BCLog::Logger::StartLogging() void BCLog::Logger::DisconnectTestLogger() { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); m_buffering = true; if (m_fileout != nullptr) fclose(m_fileout); m_fileout = nullptr; @@ -111,7 +111,7 @@ void BCLog::Logger::DisconnectTestLogger() void BCLog::Logger::DisableLogging() { { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); assert(m_buffering); assert(m_print_callbacks.empty()); } @@ -159,7 +159,7 @@ bool BCLog::Logger::WillLogCategoryLevel(BCLog::LogFlags category, BCLog::Level if (!WillLogCategory(category)) return false; - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); const auto it{m_category_log_levels.find(category)}; return level >= (it == m_category_log_levels.end() ? LogLevel() : it->second); } @@ -392,7 +392,7 @@ BCLog::LogRateLimiter::Status BCLog::LogRateLimiter::Consume( const SourceLocation& source_loc, const std::string& str) { - StdLockGuard scoped_lock(m_mutex); + STDLOCK(m_mutex); auto& stats{m_source_locations.try_emplace(source_loc, m_max_bytes).first->second}; Status status{stats.m_dropped_bytes > 0 ? Status::STILL_SUPPRESSED : Status::UNSUPPRESSED}; @@ -423,7 +423,7 @@ void BCLog::Logger::FormatLogStrInPlace(std::string& str, BCLog::LogFlags catego void BCLog::Logger::LogPrintStr(std::string_view str, SourceLocation&& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit) { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); return LogPrintStr_(str, std::move(source_loc), category, level, should_ratelimit); } @@ -556,7 +556,7 @@ void BCLog::LogRateLimiter::Reset() { decltype(m_source_locations) source_locations; { - StdLockGuard scoped_lock(m_mutex); + STDLOCK(m_mutex); source_locations.swap(m_source_locations); m_suppression_active = false; } @@ -598,7 +598,7 @@ bool BCLog::Logger::SetCategoryLogLevel(std::string_view category_str, std::stri const auto level = GetLogLevel(level_str); if (!level.has_value() || level.value() > MAX_USER_SETABLE_SEVERITY_LEVEL) return false; - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); m_category_log_levels[flag] = level.value(); return true; } diff --git a/src/logging.h b/src/logging.h index 1371c9a75b1..005c67fd83c 100644 --- a/src/logging.h +++ b/src/logging.h @@ -192,14 +192,14 @@ namespace BCLog { /** Returns whether logs will be written to any output */ bool Enabled() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs) { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); return m_buffering || m_print_to_console || m_print_to_file || !m_print_callbacks.empty(); } /** Connect a slot to the print signal and return the connection */ std::list>::iterator PushBackCallback(std::function fun) EXCLUSIVE_LOCKS_REQUIRED(!m_cs) { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); m_print_callbacks.push_back(std::move(fun)); return --m_print_callbacks.end(); } @@ -207,13 +207,13 @@ namespace BCLog { /** Delete a connection */ void DeleteCallback(std::list>::iterator it) EXCLUSIVE_LOCKS_REQUIRED(!m_cs) { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); m_print_callbacks.erase(it); } size_t NumConnections() EXCLUSIVE_LOCKS_REQUIRED(!m_cs) { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); return m_print_callbacks.size(); } @@ -224,7 +224,7 @@ namespace BCLog { void SetRateLimiting(std::shared_ptr limiter) EXCLUSIVE_LOCKS_REQUIRED(!m_cs) { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); m_limiter = std::move(limiter); } @@ -240,17 +240,17 @@ namespace BCLog { std::unordered_map CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs) { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); return m_category_log_levels; } void SetCategoryLogLevel(const std::unordered_map& levels) EXCLUSIVE_LOCKS_REQUIRED(!m_cs) { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); m_category_log_levels = levels; } void AddCategoryLogLevel(LogFlags category, Level level) EXCLUSIVE_LOCKS_REQUIRED(!m_cs) { - StdLockGuard scoped_lock(m_cs); + STDLOCK(m_cs); m_category_log_levels[category] = level; } bool SetCategoryLogLevel(std::string_view category_str, std::string_view level_str) EXCLUSIVE_LOCKS_REQUIRED(!m_cs);