diff options
author | Jason Carey <jcarey@argv.me> | 2018-08-17 11:21:21 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2018-08-21 11:24:25 -0400 |
commit | e5fd0cd67b6eabb44fbaa00a0b202eb17f7b09f8 (patch) | |
tree | 7a837d7e3ca2f33336a809be72e86e77006ca711 /src/mongo/util | |
parent | 14c53602360e9c223e70f97c2b08760df194f996 (diff) | |
download | mongo-e5fd0cd67b6eabb44fbaa00a0b202eb17f7b09f8.tar.gz |
SERVER-36676 spinlock as mutex in dbg builds linux
We have some lovely deadlock detection code built into the hang analyzer
on linux which does a great job with our internal lock types as well as
with mutexes. For debug builds, backing SpinLock's with mutexes gives us
that deadlock detection for free.
This constrains them from being released on a different thread, but
critical sections already have that property, so we can't have been
relying on it.
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/concurrency/spin_lock.cpp | 9 | ||||
-rw-r--r-- | src/mongo/util/concurrency/spin_lock.h | 25 |
2 files changed, 30 insertions, 4 deletions
diff --git a/src/mongo/util/concurrency/spin_lock.cpp b/src/mongo/util/concurrency/spin_lock.cpp index 60fbcd75486..bd4bfa2d359 100644 --- a/src/mongo/util/concurrency/spin_lock.cpp +++ b/src/mongo/util/concurrency/spin_lock.cpp @@ -27,16 +27,17 @@ * then also delete it in the license file. */ -#if !defined(_WIN32) - #include "mongo/platform/basic.h" -#include "mongo/platform/pause.h" -#include "mongo/util/concurrency/spin_lock.h" +#include "mongo/config.h" + +#if !(defined(_WIN32) || MONGO_CONFIG_DEBUG_BUILD) #include <sched.h> #include <time.h> +#include "mongo/platform/pause.h" +#include "mongo/util/concurrency/spin_lock.h" namespace mongo { diff --git a/src/mongo/util/concurrency/spin_lock.h b/src/mongo/util/concurrency/spin_lock.h index 9e4b707f160..591c059ed85 100644 --- a/src/mongo/util/concurrency/spin_lock.h +++ b/src/mongo/util/concurrency/spin_lock.h @@ -37,6 +37,7 @@ #endif #include "mongo/base/disallow_copying.h" +#include "mongo/config.h" #include "mongo/platform/compiler.h" #include "mongo/stdx/mutex.h" @@ -69,6 +70,27 @@ private: #else +#if MONGO_CONFIG_DEBUG_BUILD +class SpinLock { + MONGO_DISALLOW_COPYING(SpinLock); + +public: + SpinLock() = default; + + void lock() { + _mutex.lock(); + } + + void unlock() { + _mutex.unlock(); + } + +private: + stdx::mutex _mutex; +}; + +#else + class SpinLock { MONGO_DISALLOW_COPYING(SpinLock); @@ -96,6 +118,9 @@ private: // Initializes to the cleared state. std::atomic_flag _locked = ATOMIC_FLAG_INIT; // NOLINT }; + +#endif + #endif using scoped_spinlock = stdx::lock_guard<SpinLock>; |