1
0
Mirror von https://github.com/tkuschel/bees.git synchronisiert 2026-06-19 15:07:54 +02:00

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 <bees@furryterror.org>
Dieser Commit ist enthalten in:
Zygo Blaxell
2024-11-21 16:26:05 -05:00
Ursprung 72c3bf8438
Commit 606ac01d56
2 geänderte Dateien mit 15 neuen und 2 gelöschten Zeilen
+2
Datei anzeigen
@@ -14,6 +14,7 @@ namespace crucible {
mutex m_mutex; mutex m_mutex;
condition_variable m_cv; condition_variable m_cv;
map<string, size_t> m_counters; map<string, size_t> m_counters;
bool m_do_locking = true;
class LockHandle { class LockHandle {
const string m_type; const string m_type;
@@ -33,6 +34,7 @@ namespace crucible {
shared_ptr<LockHandle> get_lock_private(const string &type); shared_ptr<LockHandle> get_lock_private(const string &type);
public: public:
static shared_ptr<LockHandle> get_lock(const string &type); static shared_ptr<LockHandle> get_lock(const string &type);
static void enable_locking(bool enabled);
}; };
} }
+12 -1
Datei anzeigen
@@ -62,11 +62,22 @@ namespace crucible {
return rv; return rv;
} }
static MultiLocker s_process_instance;
shared_ptr<MultiLocker::LockHandle> shared_ptr<MultiLocker::LockHandle>
MultiLocker::get_lock(const string &type) MultiLocker::get_lock(const string &type)
{ {
static MultiLocker s_process_instance; if (s_process_instance.m_do_locking) {
return s_process_instance.get_lock_private(type); 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;
} }
} }