diff options
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>; |