Revert ThreadName due to problems on Windows (#4702)

* Revert "Remove CurrentThreadName.h from RippledCore.cmake (#4697)"

This reverts commit 3b5fcd5873.

* Revert "Introduce replacement for getting and setting thread name: (#4312)"

This reverts commit 36cb5f90e2.
This commit is contained in:
Howard Hinnant
2023-09-14 16:16:50 -04:00
committed by GitHub
parent 649c11a78e
commit ce570c166d
21 changed files with 207 additions and 207 deletions

View File

@@ -17,13 +17,15 @@
*/
//==============================================================================
#include <ripple/basics/ThreadUtilities.h>
#include <ripple/beast/core/CurrentThreadName.h>
#include <ripple/beast/unit_test.h>
#include <atomic>
#include <thread>
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 @@ private:
std::atomic<bool>* stop,
std::atomic<int>* 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 @@ public:
}
};
BEAST_DEFINE_TESTSUITE(ThreadName, basics, ripple);
BEAST_DEFINE_TESTSUITE(CurrentThreadName, core, beast);
} // namespace test
} // namespace ripple

View File

@@ -17,8 +17,8 @@
*/
//==============================================================================
#include <ripple/basics/ThreadUtilities.h>
#include <ripple/basics/make_SSLContext.h>
#include <ripple/beast/core/CurrentThreadName.h>
#include <ripple/beast/unit_test.h>
#include <test/jtx/envconfig.h>
@@ -630,7 +630,7 @@ public:
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(""))