From 0f4bc92f779e0768754056ee3074fbbce07786c3 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Thu, 7 Sep 2023 14:44:36 -0400 Subject: [PATCH] Introduce replacement for getting and setting thread name: (#4312) * In namespace ripple, introduces get_name function that takes a std::thread::native_handle_type and returns a std::string. * In namespace ripple, introduces get_name function that takes a std::thread or std::jthread and returns a std::string. * In namespace ripple::this_thread, introduces get_name function that takes no parameters and returns the name of the current thread as a std::string. * In namespace ripple::this_thread, introduces set_name function that takes a std::string_view and sets the name of the current thread. * Intended to replace the beast utilities setCurrentThreadName and getCurrentThreadName. --- Builds/CMake/RippledCore.cmake | 5 +- 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 +- .../ThreadUtilities.h} | 51 ++++--- src/ripple/basics/impl/ThreadUtilities.cpp | 140 ++++++++++++++++++ src/ripple/beast/core/CurrentThreadName.cpp | 125 ---------------- 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 +- .../ThreadName_test.cpp} | 19 +-- src/test/overlay/short_read_test.cpp | 4 +- 21 files changed, 208 insertions(+), 207 deletions(-) rename src/ripple/{beast/core/CurrentThreadName.h => basics/ThreadUtilities.h} (51%) create mode 100644 src/ripple/basics/impl/ThreadUtilities.cpp delete mode 100644 src/ripple/beast/core/CurrentThreadName.cpp rename src/test/{beast/beast_CurrentThreadName_test.cpp => basics/ThreadName_test.cpp} (81%) diff --git a/Builds/CMake/RippledCore.cmake b/Builds/CMake/RippledCore.cmake index 24123418a..477cfcec0 100644 --- a/Builds/CMake/RippledCore.cmake +++ b/Builds/CMake/RippledCore.cmake @@ -34,7 +34,6 @@ 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 @@ -66,6 +65,7 @@ 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 @@ -211,6 +211,7 @@ install ( src/ripple/basics/TaggedCache.h src/ripple/basics/tagged_integer.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 @@ -878,6 +879,7 @@ 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 @@ -895,7 +897,6 @@ 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 bbb3c709f..44c8debba 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 @@ private: void run() { - beast::setCurrentThreadName("LedgerCleaner"); + this_thread::set_name("LedgerCleaner"); JLOG(j_.debug()) << "Started ledger cleaner"; while (true) diff --git a/src/ripple/app/main/BasicApp.cpp b/src/ripple/app/main/BasicApp.cpp index 5993df62f..a03d7255b 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]() { - beast::setCurrentThreadName( + ripple::this_thread::set_name( "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 3a5e96b0e..eb2d4ce9a 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,9 +692,8 @@ GRPCServer::start() if (running_ = impl_.start(); running_) { thread_ = std::thread([this]() { - beast::setCurrentThreadName("rippled : GRPCServer"); // Start the event loop and begin handling requests - beast::setCurrentThreadName("rippled: grpc"); + this_thread::set_name("rippled: grpc"); this->impl_.handleRpcs(); }); } diff --git a/src/ripple/app/main/LoadManager.cpp b/src/ripple/app/main/LoadManager.cpp index 5e87063f0..df9d72f59 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() { - beast::setCurrentThreadName("LoadManager"); + this_thread::set_name("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 86b7b4827..37cf57264 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -21,9 +21,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -347,8 +347,7 @@ run(int argc, char** argv) { using namespace std; - beast::setCurrentThreadName( - "xahaud: main " + BuildInfo::getVersionString()); + this_thread::set_name("Xahaud: main " + BuildInfo::getVersionString()); po::variables_map vm; @@ -776,7 +775,7 @@ run(int argc, char** argv) } // We have an RPC command to process: - beast::setCurrentThreadName("xahaud: rpc"); + this_thread::set_name("xahaud: 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 acfa41122..d55bcb952 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 @@ -289,7 +289,7 @@ SHAMapStoreImp::run() "Reporting does not support online_delete. Remove " "online_delete info from config"); } - beast::setCurrentThreadName("SHAMapStore"); + this_thread::set_name("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 41a2b143d..5fa06ed79 100644 --- a/src/ripple/app/reporting/ETLSource.cpp +++ b/src/ripple/app/reporting/ETLSource.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include diff --git a/src/ripple/app/reporting/ReportingETL.cpp b/src/ripple/app/reporting/ReportingETL.cpp index e6887817e..0d5bd4bb7 100644 --- a/src/ripple/app/reporting/ReportingETL.cpp +++ b/src/ripple/app/reporting/ReportingETL.cpp @@ -19,8 +19,7 @@ #include #include - -#include +#include #include #include #include @@ -508,7 +507,7 @@ ReportingETL::runETLPipeline(uint32_t startSequence) &startSequence, &writeConflict, &transformQueue]() { - beast::setCurrentThreadName("rippled: ReportingETL extract"); + this_thread::set_name("ETL extract"); uint32_t currentSequence = startSequence; // there are two stopping conditions here. @@ -560,7 +559,7 @@ ReportingETL::runETLPipeline(uint32_t startSequence) &writeConflict, &loadQueue, &transformQueue]() { - beast::setCurrentThreadName("rippled: ReportingETL transform"); + this_thread::set_name("ETL transform"); assert(parent); parent = std::make_shared(*parent, NetClock::time_point{}); @@ -599,7 +598,7 @@ ReportingETL::runETLPipeline(uint32_t startSequence) &lastPublishedSequence, &loadQueue, &writeConflict]() { - beast::setCurrentThreadName("rippled: ReportingETL load"); + this_thread::set_name("ETL load"); size_t totalTransactions = 0; double totalTime = 0; while (!writeConflict) @@ -823,7 +822,7 @@ void ReportingETL::doWork() { worker_ = std::thread([this]() { - beast::setCurrentThreadName("rippled: ReportingETL worker"); + this_thread::set_name("ETL worker"); if (readOnly_) monitorReadOnly(); else diff --git a/src/ripple/beast/core/CurrentThreadName.h b/src/ripple/basics/ThreadUtilities.h similarity index 51% rename from src/ripple/beast/core/CurrentThreadName.h rename to src/ripple/basics/ThreadUtilities.h index 5adbb2108..f91dbd118 100644 --- a/src/ripple/beast/core/CurrentThreadName.h +++ b/src/ripple/basics/ThreadUtilities.h @@ -1,11 +1,7 @@ //------------------------------------------------------------------------------ /* - 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 + 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 @@ -21,31 +17,34 @@ */ //============================================================================== -#ifndef BEAST_CORE_CURRENT_THREAD_NAME_H_INCLUDED -#define BEAST_CORE_CURRENT_THREAD_NAME_H_INCLUDED +#ifndef RIPPLE_BASICS_THREADUTILITIES_H_INCLUDED +#define RIPPLE_BASICS_THREADUTILITIES_H_INCLUDED #include -#include +#include -namespace beast { +namespace ripple { -/** 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); - -/** Returns the name of the caller 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 -getCurrentThreadName(); +get_name(std::thread::native_handle_type t); -} // namespace beast +template +inline auto +get_name(Thread& t) -> decltype(t.native_handle(), t.join(), std::string{}) +{ + return get_name(t.native_handle()); +} + +namespace this_thread { + +std::string +get_name(); + +void +set_name(std::string s); + +} // namespace this_thread + +} // namespace ripple #endif diff --git a/src/ripple/basics/impl/ThreadUtilities.cpp b/src/ripple/basics/impl/ThreadUtilities.cpp new file mode 100644 index 000000000..be1745c40 --- /dev/null +++ b/src/ripple/basics/impl/ThreadUtilities.cpp @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +/* + 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 deleted file mode 100644 index 80d275a1f..000000000 --- a/src/ripple/beast/core/CurrentThreadName.cpp +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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/core/impl/Job.cpp b/src/ripple/core/impl/Job.cpp index 780a9f49c..952d513dc 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() { - beast::setCurrentThreadName("doJob: " + mName); + this_thread::set_name("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 8651dcbe5..43bd35166 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 @@ public: void doRun() { - beast::setCurrentThreadName("rippled: SNTPClock"); + this_thread::set_name("SNTPClock"); io_service_.run(); } diff --git a/src/ripple/core/impl/Workers.cpp b/src/ripple/core/impl/Workers.cpp index 732e6f0ec..aac2bf171 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 - beast::setCurrentThreadName(threadName_); + this_thread::set_name(threadName_); // Acquire a task or "internal task." // @@ -259,7 +259,7 @@ Workers::Worker::run() } // Set inactive thread name. - beast::setCurrentThreadName("(" + threadName_ + ")"); + this_thread::set_name("(" + 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 b34560dba..11979ed20 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 @@ public: std::size_t const id(++n); std::stringstream ss; ss << "rocksdb #" << id; - beast::setCurrentThreadName(ss.str()); + this_thread::set_name(ss.str()); (*f)(a); } diff --git a/src/ripple/nodestore/impl/Database.cpp b/src/ripple/nodestore/impl/Database.cpp index 70416c873..e0c82d00d 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,8 +63,7 @@ Database::Database( [this](int i) { runningThreads_++; - beast::setCurrentThreadName( - "db prefetch #" + std::to_string(i)); + this_thread::set_name("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 db5a188fc..4fe6eda2f 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() { - beast::setCurrentThreadName("perflog"); + this_thread::set_name("perflog"); lastLog_ = system_clock::now(); while (true) diff --git a/src/ripple/resource/impl/ResourceManager.cpp b/src/ripple/resource/impl/ResourceManager.cpp index 1a7e74ec1..137bbf36e 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 @@ private: void run() { - beast::setCurrentThreadName("Resource::Manager"); + this_thread::set_name("Resrc::Manager"); for (;;) { logic_.periodicActivity(); diff --git a/src/test/beast/beast_CurrentThreadName_test.cpp b/src/test/basics/ThreadName_test.cpp similarity index 81% rename from src/test/beast/beast_CurrentThreadName_test.cpp rename to src/test/basics/ThreadName_test.cpp index 6e46808f4..5cc2c1d60 100644 --- a/src/test/beast/beast_CurrentThreadName_test.cpp +++ b/src/test/basics/ThreadName_test.cpp @@ -17,15 +17,13 @@ */ //============================================================================== -#include +#include #include -#include -#include namespace ripple { namespace test { -class CurrentThreadName_test : public beast::unit_test::suite +class ThreadName_test : public beast::unit_test::suite { private: static void @@ -34,26 +32,19 @@ private: std::atomic* stop, std::atomic* state) { - // Verify that upon creation a thread has no name. - auto const initialThreadName = beast::getCurrentThreadName(); - // Set the new name. - beast::setCurrentThreadName(myName); + this_thread::set_name(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 (beast::getCurrentThreadName() == myName) + if (this_thread::get_name() == myName) *state = 2; } @@ -86,7 +77,7 @@ public: } }; -BEAST_DEFINE_TESTSUITE(CurrentThreadName, core, beast); +BEAST_DEFINE_TESTSUITE(ThreadName, basics, ripple); } // namespace test } // namespace ripple diff --git a/src/test/overlay/short_read_test.cpp b/src/test/overlay/short_read_test.cpp index 434b41008..cfcf6642d 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 @@ public: short_read_test() : work_(io_context_.get_executor()) , thread_(std::thread([this]() { - beast::setCurrentThreadName("io_context"); + this_thread::set_name("io_context"); this->io_context_.run(); })) , context_(make_SSLContext(""))