aboutsummaryrefslogtreecommitdiff
path: root/absl/synchronization/mutex.h
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2023-10-27 00:37:27 -0700
committerCopybara-Service <copybara-worker@google.com>2023-10-27 00:38:09 -0700
commitcdb1e7f4a60a6d0ee038f733776356a50121265a (patch)
treec677456c22d00eff7fbf5876a4313f165002de4b /absl/synchronization/mutex.h
parentc8087ae8bd1e8b25f4e2f38e903b1360005dc4e1 (diff)
downloadabseil-cdb1e7f4a60a6d0ee038f733776356a50121265a.tar.gz
abseil-cdb1e7f4a60a6d0ee038f733776356a50121265a.tar.bz2
abseil-cdb1e7f4a60a6d0ee038f733776356a50121265a.zip
Mutex: Remove destructor in release build
The Mutex destructor is needed only to clean up debug logging and invariant checking synch events. These are not supposed to be used in production, but the non-empty destructor has costs for production builds. Instead of removing synch events in destructor, drop all of them if we accumulated too many. For tests is should not matter (we maybe only consume a bit more memory). Production builds should be either unaffected (if don't use debug logging), or use periodic reset of all synch events. PiperOrigin-RevId: 577106805 Change-Id: Icaaf7166b99afcd5dce92b4acd1be661fb72f10b
Diffstat (limited to 'absl/synchronization/mutex.h')
-rw-r--r--absl/synchronization/mutex.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/absl/synchronization/mutex.h b/absl/synchronization/mutex.h
index 95726f6b..d8264c03 100644
--- a/absl/synchronization/mutex.h
+++ b/absl/synchronization/mutex.h
@@ -536,6 +536,7 @@ class ABSL_LOCKABLE Mutex {
void Block(base_internal::PerThreadSynch* s);
// Wake a thread; return successor.
base_internal::PerThreadSynch* Wakeup(base_internal::PerThreadSynch* w);
+ void Dtor();
friend class CondVar; // for access to Trans()/Fer().
void Trans(MuHow how); // used for CondVar->Mutex transfer
@@ -909,7 +910,6 @@ class CondVar {
// A `CondVar` allocated on the heap or on the stack can use the this
// constructor.
CondVar();
- ~CondVar();
// CondVar::Wait()
//
@@ -1061,6 +1061,15 @@ inline Mutex::Mutex() : mu_(0) {
inline constexpr Mutex::Mutex(absl::ConstInitType) : mu_(0) {}
+#if !defined(__APPLE__) && !defined(ABSL_BUILD_DLL)
+inline Mutex::~Mutex() { Dtor(); }
+#endif
+
+#if defined(NDEBUG) && !defined(ABSL_HAVE_THREAD_SANITIZER)
+// Use default (empty) destructor in release build for performance reasons.
+inline void Mutex::Dtor() {}
+#endif
+
inline CondVar::CondVar() : cv_(0) {}
// static