From 97f5b20c12ca6ccf89d7720a5d41eaf4cda1b695 Mon Sep 17 00:00:00 2001 From: stickies-v Date: Wed, 31 Aug 2022 16:30:35 +0100 Subject: [PATCH] refactor: use std::string for thread names --- src/qt/guiutil.cpp | 2 +- src/util/system.cpp | 4 ++-- src/util/system.h | 2 +- src/util/thread.cpp | 6 ++++-- src/util/thread.h | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 5cc21dd40b1..b9f0be41e30 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -982,7 +982,7 @@ void PrintSlotException( std::string description = sender->metaObject()->className(); description += "->"; description += receiver->metaObject()->className(); - PrintExceptionContinue(exception, description.c_str()); + PrintExceptionContinue(exception, description); } void ShowModalDialogAsynchronously(QDialog* dialog) diff --git a/src/util/system.cpp b/src/util/system.cpp index 1953a9f8369..8864ae73c49 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -831,7 +831,7 @@ std::string HelpMessageOpt(const std::string &option, const std::string &message std::string("\n\n"); } -static std::string FormatException(const std::exception* pex, const char* pszThread) +static std::string FormatException(const std::exception* pex, std::string_view pszThread) { #ifdef WIN32 char pszModule[MAX_PATH] = ""; @@ -847,7 +847,7 @@ static std::string FormatException(const std::exception* pex, const char* pszThr "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread); } -void PrintExceptionContinue(const std::exception* pex, const char* pszThread) +void PrintExceptionContinue(const std::exception* pex, std::string_view pszThread) { std::string message = FormatException(pex, pszThread); LogPrintf("\n\n************************\n%s\n", message); diff --git a/src/util/system.h b/src/util/system.h index 756e6642f24..5f80ca51fcf 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -51,7 +51,7 @@ bool error(const char* fmt, const Args&... args) return false; } -void PrintExceptionContinue(const std::exception *pex, const char* pszThread); +void PrintExceptionContinue(const std::exception* pex, std::string_view pszThread); /** * Ensure file contents are fully committed to disk, using a platform-specific diff --git a/src/util/thread.cpp b/src/util/thread.cpp index f9f427ba202..ae98abdb3d7 100644 --- a/src/util/thread.cpp +++ b/src/util/thread.cpp @@ -10,10 +10,12 @@ #include #include +#include +#include -void util::TraceThread(const char* thread_name, std::function thread_func) +void util::TraceThread(std::string_view thread_name, std::function thread_func) { - util::ThreadRename(thread_name); + util::ThreadRename(std::string{thread_name}); try { LogPrintf("%s thread start\n", thread_name); thread_func(); diff --git a/src/util/thread.h b/src/util/thread.h index ca2eccc0c31..b80bf046a05 100644 --- a/src/util/thread.h +++ b/src/util/thread.h @@ -6,12 +6,13 @@ #define BITCOIN_UTIL_THREAD_H #include +#include namespace util { /** * A wrapper for do-something-once thread functions. */ -void TraceThread(const char* thread_name, std::function thread_func); +void TraceThread(std::string_view thread_name, std::function thread_func); } // namespace util