From 606ac01d569851d0b1a5cbe6bc967d150bbb762c Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Thu, 21 Nov 2024 16:26:05 -0500 Subject: [PATCH] multilock: allow turning it off Add a master switch to turn off the entire MultiLock infrastructure for testing, without having to remove and add all the individual entry points. Signed-off-by: Zygo Blaxell --- include/crucible/multilock.h | 2 ++ lib/multilock.cc | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/crucible/multilock.h b/include/crucible/multilock.h index 6b7fb6c..4d55558 100644 --- a/include/crucible/multilock.h +++ b/include/crucible/multilock.h @@ -14,6 +14,7 @@ namespace crucible { mutex m_mutex; condition_variable m_cv; map m_counters; + bool m_do_locking = true; class LockHandle { const string m_type; @@ -33,6 +34,7 @@ namespace crucible { shared_ptr get_lock_private(const string &type); public: static shared_ptr get_lock(const string &type); + static void enable_locking(bool enabled); }; } diff --git a/lib/multilock.cc b/lib/multilock.cc index 8a56271..ce20dea 100644 --- a/lib/multilock.cc +++ b/lib/multilock.cc @@ -62,11 +62,22 @@ namespace crucible { return rv; } + static MultiLocker s_process_instance; + shared_ptr MultiLocker::get_lock(const string &type) { - static MultiLocker s_process_instance; - return s_process_instance.get_lock_private(type); + if (s_process_instance.m_do_locking) { + return s_process_instance.get_lock_private(type); + } else { + return shared_ptr(); + } + } + + void + MultiLocker::enable_locking(const bool enabled) + { + s_process_instance.m_do_locking = enabled; } }