diff options
author | Ben Caimano <ben.caimano@10gen.com> | 2020-02-04 16:40:20 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-02-24 19:15:57 +0000 |
commit | 1525d54f235715d10e41711122a448bd5253588d (patch) | |
tree | e03a3ee55653ff6c7ec3b5f4d95e5d58e0e06e11 /src/mongo/platform | |
parent | 1cb6ac41648ab8bcc926a1dae6345a01c735ee52 (diff) | |
download | mongo-1525d54f235715d10e41711122a448bd5253588d.tar.gz |
SERVER-46197 Make build flag to disable diagnostic latches
Diffstat (limited to 'src/mongo/platform')
-rw-r--r-- | src/mongo/platform/mutex.cpp | 14 | ||||
-rw-r--r-- | src/mongo/platform/mutex.h | 25 | ||||
-rw-r--r-- | src/mongo/platform/mutex_test.cpp | 4 |
3 files changed, 30 insertions, 13 deletions
diff --git a/src/mongo/platform/mutex.cpp b/src/mongo/platform/mutex.cpp index fd5a5dd212f..8bab12737fc 100644 --- a/src/mongo/platform/mutex.cpp +++ b/src/mongo/platform/mutex.cpp @@ -31,9 +31,9 @@ #include "mongo/base/init.h" -namespace mongo { +namespace mongo::latch_detail { -Mutex::Mutex(std::shared_ptr<latch_detail::Data> data) : _data{std::move(data)} { +Mutex::Mutex(std::shared_ptr<Data> data) : _data{std::move(data)} { invariant(_data); _data->counts().created.fetchAndAdd(1); @@ -80,7 +80,7 @@ StringData Mutex::getName() const { void Mutex::_onContendedLock() noexcept { _data->counts().contended.fetchAndAdd(1); - auto& state = latch_detail::getDiagnosticListenerState(); + auto& state = getDiagnosticListenerState(); if (!state.isFinalized.load()) { return; } @@ -93,7 +93,7 @@ void Mutex::_onContendedLock() noexcept { void Mutex::_onQuickLock() noexcept { _data->counts().acquired.fetchAndAdd(1); - auto& state = latch_detail::getDiagnosticListenerState(); + auto& state = getDiagnosticListenerState(); if (!state.isFinalized.load()) { return; } @@ -106,7 +106,7 @@ void Mutex::_onQuickLock() noexcept { void Mutex::_onSlowLock() noexcept { _data->counts().acquired.fetchAndAdd(1); - auto& state = latch_detail::getDiagnosticListenerState(); + auto& state = getDiagnosticListenerState(); if (!state.isFinalized.load()) { return; } @@ -119,7 +119,7 @@ void Mutex::_onSlowLock() noexcept { void Mutex::_onUnlock() noexcept { _data->counts().released.fetchAndAdd(1); - auto& state = latch_detail::getDiagnosticListenerState(); + auto& state = getDiagnosticListenerState(); if (!state.isFinalized.load()) { return; } @@ -141,4 +141,4 @@ MONGO_INITIALIZER(FinalizeDiagnosticListeners)(InitializerContext* context) { return Status::OK(); } -} // namespace mongo +} // namespace mongo::latch_detail diff --git a/src/mongo/platform/mutex.h b/src/mongo/platform/mutex.h index 833a33560cf..8f09f8a2463 100644 --- a/src/mongo/platform/mutex.h +++ b/src/mongo/platform/mutex.h @@ -37,6 +37,7 @@ #include "mongo/base/error_codes.h" #include "mongo/base/string_data.h" +#include "mongo/config.h" #include "mongo/platform/atomic_word.h" #include "mongo/platform/source_location.h" #include "mongo/stdx/mutex.h" @@ -49,10 +50,10 @@ namespace mongo { -class Mutex; - namespace latch_detail { +class Mutex; + using Level = hierarchical_acquisition_detail::Level; static constexpr auto kAnonymousName = "AnonymousLatch"_sd; @@ -290,7 +291,6 @@ auto getOrMakeLatchData(Tag&&, Identity identity, const SourceLocationHolder& so inline auto defaultData() { return getOrMakeLatchData([] {}, Identity(kAnonymousName), MONGO_SOURCE_LOCATION()); } -} // namespace latch_detail /** * Latch is an abstract base class that implements the Lockable concept @@ -334,8 +334,8 @@ public: bool try_lock() override; StringData getName() const override; - Mutex() : Mutex(latch_detail::defaultData()) {} - explicit Mutex(std::shared_ptr<latch_detail::Data> data); + Mutex() : Mutex(defaultData()) {} + explicit Mutex(std::shared_ptr<Data> data); ~Mutex(); @@ -345,11 +345,20 @@ private: void _onSlowLock() noexcept; void _onUnlock() noexcept; - const std::shared_ptr<latch_detail::Data> _data; + const std::shared_ptr<Data> _data; stdx::mutex _mutex; // NOLINT bool _isLocked = false; }; +} // namespace latch_detail + +#ifndef MONGO_CONFIG_USE_RAW_LATCHES +using Latch = latch_detail::Latch; +using Mutex = latch_detail::Mutex; +#else +using Latch = stdx::mutex; // NOLINT +using Mutex = stdx::mutex; // NOLINT +#endif } // namespace mongo @@ -363,4 +372,8 @@ private: /** * Construct a mongo::Mutex using the result of MONGO_GET_LATCH_DATA with all arguments forwarded */ +#ifndef MONGO_CONFIG_USE_RAW_LATCHES #define MONGO_MAKE_LATCH(...) ::mongo::Mutex(MONGO_GET_LATCH_DATA(__VA_ARGS__)); +#else +#define MONGO_MAKE_LATCH(...) ::mongo::stdx::mutex(); // NOLINT +#endif diff --git a/src/mongo/platform/mutex_test.cpp b/src/mongo/platform/mutex_test.cpp index e85f8290466..122dd58b299 100644 --- a/src/mongo/platform/mutex_test.cpp +++ b/src/mongo/platform/mutex_test.cpp @@ -29,6 +29,7 @@ #include "mongo/unittest/unittest.h" +#include "mongo/config.h" #include "mongo/platform/mutex.h" namespace mongo { @@ -41,6 +42,7 @@ TEST(MutexTest, BasicSingleThread) { m.unlock(); } +#ifndef MONGO_CONFIG_USE_RAW_LATCHES namespace { // Since this MONGO_MAKE_LATCH has no arguments, the mutex is anonymous auto gMutex = MONGO_MAKE_LATCH(); @@ -65,4 +67,6 @@ TEST(MutexTest, Macros) { static_assert(std::is_same_v<decltype(gMutex), Mutex>); ASSERT_EQ(gMutex.getName(), latch_detail::kAnonymousName); } +#endif + } // namespace mongo |