]> git.hungrycats.org Git - bees/commitdiff
multilock: allow turning it off
authorZygo Blaxell <bees@furryterror.org>
Thu, 21 Nov 2024 21:26:05 +0000 (16:26 -0500)
committerZygo Blaxell <bees@furryterror.org>
Sun, 1 Dec 2024 04:30:33 +0000 (23:30 -0500)
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 <bees@furryterror.org>
include/crucible/multilock.h
lib/multilock.cc

index 6b7fb6ccbc99b5cc65676e07e2b9230623de5af8..4d55558a8ea198a44ab63c70809ef74030e09628 100644 (file)
@@ -14,6 +14,7 @@ namespace crucible {
                mutex m_mutex;
                condition_variable m_cv;
                map<string, size_t> m_counters;
+               bool m_do_locking = true;
 
                class LockHandle {
                        const string m_type;
@@ -33,6 +34,7 @@ namespace crucible {
                shared_ptr<LockHandle> get_lock_private(const string &type);
        public:
                static shared_ptr<LockHandle> get_lock(const string &type);
+               static void enable_locking(bool enabled);
        };
 
 }
index 8a56271b7206e5a3b03eb06a30a22b828e8998d3..ce20dea746b3993ac54ae910994a2badfab0bc86 100644 (file)
@@ -62,11 +62,22 @@ namespace crucible {
                return rv;
        }
 
+       static MultiLocker s_process_instance;
+
        shared_ptr<MultiLocker::LockHandle>
        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<MultiLocker::LockHandle>();
+               }
+       }
+
+       void
+       MultiLocker::enable_locking(const bool enabled)
+       {
+               s_process_instance.m_do_locking = enabled;
        }
 
 }