diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2022-05-13 04:01:14 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-13 04:58:26 +0000 |
commit | 95edbf51b92e6944043590fe781c901d2a815f9f (patch) | |
tree | f0c7e827152480a01f1485c11b4bbbb6f6ef078a /src/mongo/db | |
parent | 33ced84ad3537acb5a70907b6febb34adbcfbbcc (diff) | |
download | mongo-95edbf51b92e6944043590fe781c901d2a815f9f.tar.gz |
SERVER-63852 ThreadName rewrite
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/client.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/client.h | 2 | ||||
-rw-r--r-- | src/mongo/db/client_strand.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/client_strand.h | 6 | ||||
-rw-r--r-- | src/mongo/db/client_strand_test.cpp | 12 |
5 files changed, 15 insertions, 15 deletions
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index 7da46be32df..acf26319b39 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -188,14 +188,14 @@ ThreadClient::ThreadClient(StringData desc, ServiceContext* serviceContext, transport::SessionHandle session) { invariantNoCurrentClient(); - _originalThreadName = ThreadName::get(ThreadContext::get()); + _originalThreadName = getThreadNameRef(); Client::initThread(desc, serviceContext, std::move(session)); } ThreadClient::~ThreadClient() { invariant(currentClient); currentClient.reset(nullptr); - ThreadName::set(ThreadContext::get(), _originalThreadName); + setThreadNameRef(std::move(_originalThreadName)); } Client* ThreadClient::get() const { diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h index af203a5255e..9f566763a93 100644 --- a/src/mongo/db/client.h +++ b/src/mongo/db/client.h @@ -337,7 +337,7 @@ public: } private: - boost::intrusive_ptr<ThreadName> _originalThreadName; + ThreadNameRef _originalThreadName; }; /** diff --git a/src/mongo/db/client_strand.cpp b/src/mongo/db/client_strand.cpp index 41aa4af3d9e..f4bd5665540 100644 --- a/src/mongo/db/client_strand.cpp +++ b/src/mongo/db/client_strand.cpp @@ -69,7 +69,7 @@ void ClientStrand::_setCurrent() noexcept { Client::setCurrent(std::move(_client)); // Set up the thread name. - _oldThreadName = ThreadName::set(ThreadContext::get(), _threadName); + _oldThreadName = setThreadNameRef(_threadName); if (_oldThreadName) { LOGV2_DEBUG(5127802, kDiagnosticLogLevel, "Set thread name", "name"_attr = *_threadName); } @@ -85,10 +85,10 @@ void ClientStrand::_releaseCurrent() noexcept { if (_oldThreadName) { // Reset the last thread name because it was previously set in the OS. - ThreadName::set(ThreadContext::get(), std::move(_oldThreadName)); + setThreadNameRef(std::move(_oldThreadName)); } else { // Release the thread name for reuse. - ThreadName::release(ThreadContext::get()); + releaseThreadNameRef(); } LOGV2_DEBUG( diff --git a/src/mongo/db/client_strand.h b/src/mongo/db/client_strand.h index cab3140671d..334e29a7c15 100644 --- a/src/mongo/db/client_strand.h +++ b/src/mongo/db/client_strand.h @@ -133,7 +133,7 @@ public: ClientStrand(ServiceContext::UniqueClient client) : _clientPtr(client.get()), _client(std::move(client)), - _threadName(make_intrusive<ThreadName>(_client->desc())) {} + _threadName(ThreadNameRef{_client->desc()}) {} /** * Get a pointer to the underlying Client. @@ -204,8 +204,8 @@ private: ServiceContext::UniqueClient _client; - boost::intrusive_ptr<ThreadName> _threadName; - boost::intrusive_ptr<ThreadName> _oldThreadName; + ThreadNameRef _threadName; + ThreadNameRef _oldThreadName; }; inline void ClientStrand::Executor::schedule(Task task) { diff --git a/src/mongo/db/client_strand_test.cpp b/src/mongo/db/client_strand_test.cpp index cce87321862..661b03ea8cd 100644 --- a/src/mongo/db/client_strand_test.cpp +++ b/src/mongo/db/client_strand_test.cpp @@ -54,7 +54,7 @@ public: * Clean up any leftover thread_local pieces. */ void releaseClient() { - ThreadName::release(ThreadContext::get()); + releaseThreadNameRef(); if (haveClient()) { Client::releaseCurrent(); } @@ -123,7 +123,7 @@ TEST_F(ClientStrandTest, BindMultipleTimes) { // We have no bound Client. assertStrandNotBound(strand); - for (auto i = 0; i < 100; ++i) { + for (auto i = 0; i < 10; ++i) { // Bind a bunch of times. { @@ -145,7 +145,7 @@ TEST_F(ClientStrandTest, BindMultipleTimesAndDismiss) { assertStrandNotBound(strand); auto guard = strand->bind(); - for (auto i = 0; i < 100; ++i) { + for (auto i = 0; i < 10; ++i) { assertStrandBound(strand); // Dismiss the current guard. @@ -266,7 +266,7 @@ TEST_F(ClientStrandTest, BindLocalAfterWorkerThread) { TEST_F(ClientStrandTest, BindManyWorkerThreads) { auto strand = ClientStrand::make(getServiceContext()->makeClient(kClientName1)); - constexpr size_t kCount = 100; + constexpr size_t kCount = 10; auto barrier = std::make_shared<unittest::Barrier>(kCount); size_t threadsBound = 0; @@ -308,7 +308,7 @@ TEST_F(ClientStrandTest, SwapStrands) { assertStrandNotBound(strand1); assertStrandNotBound(strand2); - for (size_t i = 0; i < 100; ++i) { + for (size_t i = 0; i < 10; ++i) { // Alternate between binding strand1 and strand2. Start on strand2 so it has a different // thread name than the previous test. auto& strand = (i % 2 == 0) ? strand2 : strand1; @@ -325,7 +325,7 @@ TEST_F(ClientStrandTest, SwapStrands) { } TEST_F(ClientStrandTest, Executor) { - constexpr size_t kCount = 100; + constexpr size_t kCount = 10; auto strand = ClientStrand::make(getServiceContext()->makeClient(kClientName1)); |