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; } }