From ce570c166d98e06b1ba22eda26ec7855789a5ca7 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Thu, 14 Sep 2023 16:16:50 -0400 Subject: [PATCH] Revert ThreadName due to problems on Windows (#4702) * Revert "Remove CurrentThreadName.h from RippledCore.cmake (#4697)" This reverts commit 3b5fcd587313f5ebc762bc21c6a4ec3e6c275e83. * Revert "Introduce replacement for getting and setting thread name: (#4312)" This reverts commit 36cb5f90e233f975eb3f80d819b2fbadab0a9387. --- Builds/CMake/RippledCore.cmake | 6 +- src/ripple/app/ledger/impl/LedgerCleaner.cpp | 4 +- src/ripple/app/main/BasicApp.cpp | 4 +- src/ripple/app/main/GRPCServer.cpp | 5 +- src/ripple/app/main/LoadManager.cpp | 4 +- src/ripple/app/main/Main.cpp | 7 +- src/ripple/app/misc/SHAMapStoreImp.cpp | 4 +- src/ripple/app/reporting/ETLSource.cpp | 1 + src/ripple/app/reporting/ReportingETL.cpp | 11 +- src/ripple/basics/impl/ThreadUtilities.cpp | 140 ------------------ src/ripple/beast/core/CurrentThreadName.cpp | 125 ++++++++++++++++ .../core/CurrentThreadName.h} | 45 +++--- src/ripple/core/impl/Job.cpp | 4 +- src/ripple/core/impl/SNTPClock.cpp | 4 +- src/ripple/core/impl/Workers.cpp | 6 +- .../nodestore/backend/RocksDBFactory.cpp | 4 +- src/ripple/nodestore/impl/Database.cpp | 5 +- src/ripple/perflog/impl/PerfLogImp.cpp | 4 +- src/ripple/resource/impl/ResourceManager.cpp | 4 +- .../beast_CurrentThreadName_test.cpp} | 19 ++- src/test/overlay/short_read_test.cpp | 4 +- 21 files changed, 205 insertions(+), 205 deletions(-) delete mode 100644 src/ripple/basics/impl/ThreadUtilities.cpp create mode 100644 src/ripple/beast/core/CurrentThreadName.cpp rename src/ripple/{basics/ThreadUtilities.h => beast/core/CurrentThreadName.h} (51%) rename src/test/{basics/ThreadName_test.cpp => beast/beast_CurrentThreadName_test.cpp} (81%) diff --git a/Builds/CMake/RippledCore.cmake b/Builds/CMake/RippledCore.cmake index 1cc9bb6de50..95c5e411631 100644 --- a/Builds/CMake/RippledCore.cmake +++ b/Builds/CMake/RippledCore.cmake @@ -24,6 +24,7 @@ add_library(xrpl::libxrpl ALIAS libxrpl) #]===============================] target_sources (xrpl_core PRIVATE src/ripple/beast/clock/basic_seconds_clock.cpp + src/ripple/beast/core/CurrentThreadName.cpp src/ripple/beast/core/SemanticVersion.cpp src/ripple/beast/hash/impl/xxhash.cpp src/ripple/beast/insight/impl/Collector.cpp @@ -55,7 +56,6 @@ target_sources (xrpl_core PRIVATE src/ripple/basics/impl/Log.cpp src/ripple/basics/impl/Number.cpp src/ripple/basics/impl/StringUtilities.cpp - src/ripple/basics/impl/ThreadUtilities.cpp #[===============================[ main sources: subdir: json @@ -203,7 +203,6 @@ install ( src/ripple/basics/tagged_integer.h src/ripple/basics/SubmitSync.h src/ripple/basics/ThreadSafetyAnalysis.h - src/ripple/basics/ThreadUtilities.h src/ripple/basics/ToString.h src/ripple/basics/UnorderedContainers.h src/ripple/basics/UptimeClock.h @@ -315,6 +314,7 @@ install ( DESTINATION include/ripple/beast/clock) install ( FILES + src/ripple/beast/core/CurrentThreadName.h src/ripple/beast/core/LexicalCast.h src/ripple/beast/core/List.h src/ripple/beast/core/SemanticVersion.h @@ -846,7 +846,6 @@ if (tests) src/test/basics/Slice_test.cpp src/test/basics/StringUtilities_test.cpp src/test/basics/TaggedCache_test.cpp - src/test/basics/ThreadName_test.cpp src/test/basics/XRPAmount_test.cpp src/test/basics/base64_test.cpp src/test/basics/base_uint_test.cpp @@ -864,6 +863,7 @@ if (tests) src/test/beast/LexicalCast_test.cpp src/test/beast/SemanticVersion_test.cpp src/test/beast/aged_associative_container_test.cpp + src/test/beast/beast_CurrentThreadName_test.cpp src/test/beast/beast_Journal_test.cpp src/test/beast/beast_PropertyStream_test.cpp src/test/beast/beast_Zero_test.cpp diff --git a/src/ripple/app/ledger/impl/LedgerCleaner.cpp b/src/ripple/app/ledger/impl/LedgerCleaner.cpp index d63c24476d7..e5ee6409d34 100644 --- a/src/ripple/app/ledger/impl/LedgerCleaner.cpp +++ b/src/ripple/app/ledger/impl/LedgerCleaner.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include namespace ripple { @@ -218,7 +218,7 @@ class LedgerCleanerImp : public LedgerCleaner void run() { - this_thread::set_name("LedgerCleaner"); + beast::setCurrentThreadName("LedgerCleaner"); JLOG(j_.debug()) << "Started"; while (true) diff --git a/src/ripple/app/main/BasicApp.cpp b/src/ripple/app/main/BasicApp.cpp index a03d7255b3e..5993df62fa7 100644 --- a/src/ripple/app/main/BasicApp.cpp +++ b/src/ripple/app/main/BasicApp.cpp @@ -18,7 +18,7 @@ //============================================================================== #include -#include +#include BasicApp::BasicApp(std::size_t numberOfThreads) { @@ -28,7 +28,7 @@ BasicApp::BasicApp(std::size_t numberOfThreads) while (numberOfThreads--) { threads_.emplace_back([this, numberOfThreads]() { - ripple::this_thread::set_name( + beast::setCurrentThreadName( "io svc #" + std::to_string(numberOfThreads)); this->io_service_.run(); }); diff --git a/src/ripple/app/main/GRPCServer.cpp b/src/ripple/app/main/GRPCServer.cpp index eb2d4ce9a18..3a5e96b0ed9 100644 --- a/src/ripple/app/main/GRPCServer.cpp +++ b/src/ripple/app/main/GRPCServer.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include @@ -692,8 +692,9 @@ GRPCServer::start() if (running_ = impl_.start(); running_) { thread_ = std::thread([this]() { + beast::setCurrentThreadName("rippled : GRPCServer"); // Start the event loop and begin handling requests - this_thread::set_name("rippled: grpc"); + beast::setCurrentThreadName("rippled: grpc"); this->impl_.handleRpcs(); }); } diff --git a/src/ripple/app/main/LoadManager.cpp b/src/ripple/app/main/LoadManager.cpp index df9d72f599a..5e87063f000 100644 --- a/src/ripple/app/main/LoadManager.cpp +++ b/src/ripple/app/main/LoadManager.cpp @@ -21,8 +21,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -99,7 +99,7 @@ LoadManager::stop() void LoadManager::run() { - this_thread::set_name("LoadManager"); + beast::setCurrentThreadName("LoadManager"); using namespace std::chrono_literals; using clock_type = std::chrono::steady_clock; diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index 84c74b8924d..80ac40132d5 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -22,9 +22,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -348,7 +348,8 @@ run(int argc, char** argv) { using namespace std; - this_thread::set_name("main " + BuildInfo::getVersionString()); + beast::setCurrentThreadName( + "rippled: main " + BuildInfo::getVersionString()); po::variables_map vm; @@ -826,7 +827,7 @@ run(int argc, char** argv) } // We have an RPC command to process: - this_thread::set_name("rippled: rpc"); + beast::setCurrentThreadName("rippled: rpc"); return RPCCall::fromCommandLine( *config, vm["parameters"].as>(), *logs); } diff --git a/src/ripple/app/misc/SHAMapStoreImp.cpp b/src/ripple/app/misc/SHAMapStoreImp.cpp index f396144cfd5..d5cb07792dc 100644 --- a/src/ripple/app/misc/SHAMapStoreImp.cpp +++ b/src/ripple/app/misc/SHAMapStoreImp.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -286,7 +286,7 @@ SHAMapStoreImp::run() "Reporting does not support online_delete. Remove " "online_delete info from config"); } - this_thread::set_name("SHAMapStore"); + beast::setCurrentThreadName("SHAMapStore"); LedgerIndex lastRotated = state_db_.getState().lastRotated; netOPs_ = &app_.getOPs(); ledgerMaster_ = &app_.getLedgerMaster(); diff --git a/src/ripple/app/reporting/ETLSource.cpp b/src/ripple/app/reporting/ETLSource.cpp index 213b17737b4..be31f4fdfa9 100644 --- a/src/ripple/app/reporting/ETLSource.cpp +++ b/src/ripple/app/reporting/ETLSource.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include diff --git a/src/ripple/app/reporting/ReportingETL.cpp b/src/ripple/app/reporting/ReportingETL.cpp index 0b68ae1ffa1..d8d6af36881 100644 --- a/src/ripple/app/reporting/ReportingETL.cpp +++ b/src/ripple/app/reporting/ReportingETL.cpp @@ -19,7 +19,8 @@ #include #include -#include + +#include #include #include #include @@ -509,7 +510,7 @@ ReportingETL::runETLPipeline(uint32_t startSequence) &startSequence, &writeConflict, &transformQueue]() { - this_thread::set_name("ETL extract"); + beast::setCurrentThreadName("rippled: ReportingETL extract"); uint32_t currentSequence = startSequence; // there are two stopping conditions here. @@ -561,7 +562,7 @@ ReportingETL::runETLPipeline(uint32_t startSequence) &writeConflict, &loadQueue, &transformQueue]() { - this_thread::set_name("ETL transform"); + beast::setCurrentThreadName("rippled: ReportingETL transform"); assert(parent); parent = std::make_shared(*parent, NetClock::time_point{}); @@ -600,7 +601,7 @@ ReportingETL::runETLPipeline(uint32_t startSequence) &lastPublishedSequence, &loadQueue, &writeConflict]() { - this_thread::set_name("ETL load"); + beast::setCurrentThreadName("rippled: ReportingETL load"); size_t totalTransactions = 0; double totalTime = 0; while (!writeConflict) @@ -824,7 +825,7 @@ void ReportingETL::doWork() { worker_ = std::thread([this]() { - this_thread::set_name("ETL worker"); + beast::setCurrentThreadName("rippled: ReportingETL worker"); if (readOnly_) monitorReadOnly(); else diff --git a/src/ripple/basics/impl/ThreadUtilities.cpp b/src/ripple/basics/impl/ThreadUtilities.cpp deleted file mode 100644 index be1745c40a7..00000000000 --- a/src/ripple/basics/impl/ThreadUtilities.cpp +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2022 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include -#include - -namespace ripple { - -#ifdef __APPLE__ - -#include - -std::string -get_name(std::thread::native_handle_type t) -{ - char buffer[64]; - if (pthread_getname_np(t, buffer, sizeof(buffer)) != 0) - throw std::runtime_error("get_name failed\n"); - return buffer; -} - -namespace this_thread { - -std::string -get_name() -{ - return ripple::get_name(pthread_self()); -} - -void -set_name(std::string s) -{ - s.resize(15); - if (pthread_setname_np(s.data()) != 0) - throw std::runtime_error("this_thread::set_name failed\n"); -} - -} // namespace this_thread - -#endif // __APPLE__ - -#ifdef __linux__ - -#include - -std::string -get_name(std::thread::native_handle_type t) -{ - char buffer[64]; - if (pthread_getname_np(t, buffer, sizeof(buffer)) != 0) - throw std::runtime_error("get_name failed\n"); - return buffer; -} - -namespace this_thread { - -std::string -get_name() -{ - return ripple::get_name(pthread_self()); -} - -void -set_name(std::string s) -{ - s.resize(15); - if (pthread_setname_np(pthread_self(), s.data()) != 0) - throw std::runtime_error("this_thread::set_name failed\n"); -} - -} // namespace this_thread - -#endif // __linux__ - -#ifdef _WIN64 - -#define WIN32_LEAN_AND_MEAN - -#include -#include -#include - -std::string -get_name(std::thread::native_handle_type t) -{ - wchar_t* unhandled_data{}; - HRESULT r = GetThreadDescription(t, &unhandled_data); - std::unique_ptr data{ - unhandled_data, LocalFree}; - if (FAILED(r)) - throw std::runtime_error("get_name failed\n"); - std::string s; - auto p = data.get(); - while (*p) - s.push_back(static_cast(*p++)); - return s; -} - -namespace this_thread { - -std::string -get_name() -{ - return ripple::get_name(GetCurrentThread()); -} - -void -set_name(std::string s) -{ - assert(s.size() <= 15); - s.resize(15); - std::wstring ws; - for (auto c : s) - ws += c; - HRESULT r = SetThreadDescription(GetCurrentThread(), ws.data()); - if (FAILED(r)) - throw std::runtime_error("this_thread::set_name failed\n"); -} - -} // namespace this_thread - -#endif // __WINDOWS__ - -} // namespace ripple diff --git a/src/ripple/beast/core/CurrentThreadName.cpp b/src/ripple/beast/core/CurrentThreadName.cpp new file mode 100644 index 00000000000..80d275a1fff --- /dev/null +++ b/src/ripple/beast/core/CurrentThreadName.cpp @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Portions of this file are from JUCE. + Copyright (c) 2013 - Raw Material Software Ltd. + Please visit http://www.juce.com + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include +#include + +//------------------------------------------------------------------------------ + +#if BOOST_OS_WINDOWS +#include +#include + +namespace beast::detail { + +inline void +setCurrentThreadNameImpl(std::string_view name) +{ +#if DEBUG && BOOST_COMP_MSVC + // This technique is documented by Microsoft and works for all versions + // of Windows and Visual Studio provided that the process is being run + // under the Visual Studio debugger. For more details, see: + // https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code + +#pragma pack(push, 8) + struct THREADNAME_INFO + { + DWORD dwType; + LPCSTR szName; + DWORD dwThreadID; + DWORD dwFlags; + }; +#pragma pack(pop) + + THREADNAME_INFO ni; + + ni.dwType = 0x1000; + ni.szName = name.data(); + ni.dwThreadID = GetCurrentThreadId(); + ni.dwFlags = 0; + +#pragma warning(push) +#pragma warning(disable : 6320 6322) + __try + { + RaiseException( + 0x406d1388, 0, sizeof(ni) / sizeof(ULONG_PTR), (ULONG_PTR*)&ni); + } + __except (EXCEPTION_CONTINUE_EXECUTION) + { + } +#pragma warning(pop) +#endif +} + +} // namespace beast::detail +#endif // BOOST_OS_WINDOWS + +#if BOOST_OS_MACOS +#include + +namespace beast::detail { + +inline void +setCurrentThreadNameImpl(std::string_view name) +{ + pthread_setname_np(name.data()); +} + +} // namespace beast::detail +#endif // BOOST_OS_MACOS + +#if BOOST_OS_LINUX +#include + +namespace beast::detail { + +inline void +setCurrentThreadNameImpl(std::string_view name) +{ + pthread_setname_np(pthread_self(), name.data()); +} + +} // namespace beast::detail +#endif // BOOST_OS_LINUX + +namespace beast { + +namespace detail { +thread_local std::string threadName; +} // namespace detail + +std::string +getCurrentThreadName() +{ + return detail::threadName; +} + +void +setCurrentThreadName(std::string_view name) +{ + detail::threadName = name; + detail::setCurrentThreadNameImpl(name); +} + +} // namespace beast diff --git a/src/ripple/basics/ThreadUtilities.h b/src/ripple/beast/core/CurrentThreadName.h similarity index 51% rename from src/ripple/basics/ThreadUtilities.h rename to src/ripple/beast/core/CurrentThreadName.h index f91dbd118e4..5adbb210880 100644 --- a/src/ripple/basics/ThreadUtilities.h +++ b/src/ripple/beast/core/CurrentThreadName.h @@ -1,7 +1,11 @@ //------------------------------------------------------------------------------ /* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2022 Ripple Labs Inc. + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Portions of this file are from JUCE. + Copyright (c) 2013 - Raw Material Software Ltd. + Please visit http://www.juce.com Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -17,34 +21,31 @@ */ //============================================================================== -#ifndef RIPPLE_BASICS_THREADUTILITIES_H_INCLUDED -#define RIPPLE_BASICS_THREADUTILITIES_H_INCLUDED +#ifndef BEAST_CORE_CURRENT_THREAD_NAME_H_INCLUDED +#define BEAST_CORE_CURRENT_THREAD_NAME_H_INCLUDED #include -#include +#include -namespace ripple { +namespace beast { -std::string -get_name(std::thread::native_handle_type t); +/** Changes the name of the caller thread. + Different OSes may place different length or content limits on this name. +*/ +void +setCurrentThreadName(std::string_view newThreadName); -template -inline auto -get_name(Thread& t) -> decltype(t.native_handle(), t.join(), std::string{}) -{ - return get_name(t.native_handle()); -} +/** Returns the name of the caller thread. -namespace this_thread { + The name returned is the name as set by a call to setCurrentThreadName(). + If the thread name is set by an external force, then that name change + will not be reported. + If no name has ever been set, then the empty string is returned. +*/ std::string -get_name(); - -void -set_name(std::string s); - -} // namespace this_thread +getCurrentThreadName(); -} // namespace ripple +} // namespace beast #endif diff --git a/src/ripple/core/impl/Job.cpp b/src/ripple/core/impl/Job.cpp index 952d513dc16..780a9f49cdf 100644 --- a/src/ripple/core/impl/Job.cpp +++ b/src/ripple/core/impl/Job.cpp @@ -17,7 +17,7 @@ */ //============================================================================== -#include +#include #include #include @@ -61,7 +61,7 @@ Job::queue_time() const void Job::doJob() { - this_thread::set_name("doJob: " + mName); + beast::setCurrentThreadName("doJob: " + mName); m_loadEvent->start(); m_loadEvent->setName(mName); diff --git a/src/ripple/core/impl/SNTPClock.cpp b/src/ripple/core/impl/SNTPClock.cpp index 43bd35166df..8651dcbe5a4 100644 --- a/src/ripple/core/impl/SNTPClock.cpp +++ b/src/ripple/core/impl/SNTPClock.cpp @@ -18,8 +18,8 @@ //============================================================================== #include -#include #include +#include #include #include #include @@ -193,7 +193,7 @@ class SNTPClientImp : public SNTPClock void doRun() { - this_thread::set_name("SNTPClock"); + beast::setCurrentThreadName("rippled: SNTPClock"); io_service_.run(); } diff --git a/src/ripple/core/impl/Workers.cpp b/src/ripple/core/impl/Workers.cpp index aac2bf1716a..732e6f0ec8a 100644 --- a/src/ripple/core/impl/Workers.cpp +++ b/src/ripple/core/impl/Workers.cpp @@ -18,7 +18,7 @@ //============================================================================== #include -#include +#include #include #include @@ -206,7 +206,7 @@ Workers::Worker::run() for (;;) { // Put the name back in case the callback changed it - this_thread::set_name(threadName_); + beast::setCurrentThreadName(threadName_); // Acquire a task or "internal task." // @@ -259,7 +259,7 @@ Workers::Worker::run() } // Set inactive thread name. - this_thread::set_name("(" + threadName_ + ")"); + beast::setCurrentThreadName("(" + threadName_ + ")"); // [1] We will be here when the paused list is popped // diff --git a/src/ripple/nodestore/backend/RocksDBFactory.cpp b/src/ripple/nodestore/backend/RocksDBFactory.cpp index 11979ed2019..b34560dba89 100644 --- a/src/ripple/nodestore/backend/RocksDBFactory.cpp +++ b/src/ripple/nodestore/backend/RocksDBFactory.cpp @@ -22,9 +22,9 @@ #if RIPPLE_ROCKSDB_AVAILABLE #include -#include #include #include +#include #include // VFALCO Bad dependency #include #include @@ -67,7 +67,7 @@ class RocksDBEnv : public rocksdb::EnvWrapper std::size_t const id(++n); std::stringstream ss; ss << "rocksdb #" << id; - this_thread::set_name(ss.str()); + beast::setCurrentThreadName(ss.str()); (*f)(a); } diff --git a/src/ripple/nodestore/impl/Database.cpp b/src/ripple/nodestore/impl/Database.cpp index e0c82d00d03..70416c873d5 100644 --- a/src/ripple/nodestore/impl/Database.cpp +++ b/src/ripple/nodestore/impl/Database.cpp @@ -18,8 +18,8 @@ //============================================================================== #include -#include #include +#include #include #include #include @@ -63,7 +63,8 @@ Database::Database( [this](int i) { runningThreads_++; - this_thread::set_name("prefetch " + std::to_string(i)); + beast::setCurrentThreadName( + "db prefetch #" + std::to_string(i)); decltype(read_) read; diff --git a/src/ripple/perflog/impl/PerfLogImp.cpp b/src/ripple/perflog/impl/PerfLogImp.cpp index 4fe6eda2fc5..db5a188fc3e 100644 --- a/src/ripple/perflog/impl/PerfLogImp.cpp +++ b/src/ripple/perflog/impl/PerfLogImp.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include #include @@ -255,7 +255,7 @@ PerfLogImp::openLog() void PerfLogImp::run() { - this_thread::set_name("perflog"); + beast::setCurrentThreadName("perflog"); lastLog_ = system_clock::now(); while (true) diff --git a/src/ripple/resource/impl/ResourceManager.cpp b/src/ripple/resource/impl/ResourceManager.cpp index 137bbf36eb7..1a7e74ec1f8 100644 --- a/src/ripple/resource/impl/ResourceManager.cpp +++ b/src/ripple/resource/impl/ResourceManager.cpp @@ -18,8 +18,8 @@ //============================================================================== #include -#include #include +#include #include #include #include @@ -149,7 +149,7 @@ class ManagerImp : public Manager void run() { - this_thread::set_name("Resrc::Manager"); + beast::setCurrentThreadName("Resource::Manager"); for (;;) { logic_.periodicActivity(); diff --git a/src/test/basics/ThreadName_test.cpp b/src/test/beast/beast_CurrentThreadName_test.cpp similarity index 81% rename from src/test/basics/ThreadName_test.cpp rename to src/test/beast/beast_CurrentThreadName_test.cpp index 5cc2c1d609f..6e46808f4b2 100644 --- a/src/test/basics/ThreadName_test.cpp +++ b/src/test/beast/beast_CurrentThreadName_test.cpp @@ -17,13 +17,15 @@ */ //============================================================================== -#include +#include #include +#include +#include namespace ripple { namespace test { -class ThreadName_test : public beast::unit_test::suite +class CurrentThreadName_test : public beast::unit_test::suite { private: static void @@ -32,19 +34,26 @@ class ThreadName_test : public beast::unit_test::suite std::atomic* stop, std::atomic* state) { + // Verify that upon creation a thread has no name. + auto const initialThreadName = beast::getCurrentThreadName(); + // Set the new name. - this_thread::set_name(myName); + beast::setCurrentThreadName(myName); // Indicate to caller that the name is set. *state = 1; + // If there is an initial thread name then we failed. + if (!initialThreadName.empty()) + return; + // Wait until all threads have their names. while (!*stop) ; // Make sure the thread name that we set before is still there // (not overwritten by, for instance, another thread). - if (this_thread::get_name() == myName) + if (beast::getCurrentThreadName() == myName) *state = 2; } @@ -77,7 +86,7 @@ class ThreadName_test : public beast::unit_test::suite } }; -BEAST_DEFINE_TESTSUITE(ThreadName, basics, ripple); +BEAST_DEFINE_TESTSUITE(CurrentThreadName, core, beast); } // namespace test } // namespace ripple diff --git a/src/test/overlay/short_read_test.cpp b/src/test/overlay/short_read_test.cpp index cfcf6642d94..434b4100852 100644 --- a/src/test/overlay/short_read_test.cpp +++ b/src/test/overlay/short_read_test.cpp @@ -17,8 +17,8 @@ */ //============================================================================== -#include #include +#include #include #include @@ -630,7 +630,7 @@ class short_read_test : public beast::unit_test::suite short_read_test() : work_(io_context_.get_executor()) , thread_(std::thread([this]() { - this_thread::set_name("io_context"); + beast::setCurrentThreadName("io_context"); this->io_context_.run(); })) , context_(make_SSLContext(""))