diff options
author | Ben Caimano <ben.caimano@10gen.com> | 2020-11-12 19:13:44 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-12-03 20:34:08 +0000 |
commit | b0f7369dfb3bd61db0cf08c4f2373788fbf01a67 (patch) | |
tree | 78806650721981bd46bcd21257128c90badbf78a /src/mongo/db/client_strand.cpp | |
parent | ab78fd25adaea0603cf9497c1acc0d88cb739b84 (diff) | |
download | mongo-b0f7369dfb3bd61db0cf08c4f2373788fbf01a67.tar.gz |
SERVER-52821 Allow thread names to be cached by unique id
Diffstat (limited to 'src/mongo/db/client_strand.cpp')
-rw-r--r-- | src/mongo/db/client_strand.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/mongo/db/client_strand.cpp b/src/mongo/db/client_strand.cpp index 1455485ebf9..97b3d92bfaf 100644 --- a/src/mongo/db/client_strand.cpp +++ b/src/mongo/db/client_strand.cpp @@ -35,6 +35,7 @@ #include "mongo/logv2/log.h" #include "mongo/util/concurrency/thread_name.h" +#include "mongo/util/thread_context.h" namespace mongo { namespace { @@ -66,12 +67,9 @@ void ClientStrand::_setCurrent() noexcept { Client::setCurrent(std::move(_client)); // Set up the thread name. - auto oldThreadName = getThreadName(); - StringData threadName = _clientPtr->desc(); - if (oldThreadName != threadName) { - _oldThreadName = oldThreadName.toString(); - setThreadName(threadName); - LOGV2_DEBUG(5127802, kDiagnosticLogLevel, "Set thread name", "name"_attr = threadName); + _oldThreadName = ThreadName::set(ThreadContext::get(), _threadName); + if (_oldThreadName) { + LOGV2_DEBUG(5127802, kDiagnosticLogLevel, "Set thread name", "name"_attr = *_threadName); } } @@ -83,9 +81,12 @@ void ClientStrand::_releaseCurrent() noexcept { _client = Client::releaseCurrent(); invariant(_client.get() == _clientPtr, kUnableToRecoverClient); - if (!_oldThreadName.empty()) { - // Reset the old thread name. - setThreadName(_oldThreadName); + if (_oldThreadName) { + // Reset the last thread name because it was previously set in the OS. + ThreadName::set(ThreadContext::get(), std::move(_oldThreadName)); + } else { + // Release the thread name for reuse. + ThreadName::release(ThreadContext::get()); } LOGV2_DEBUG( |