#ifndef CRUCIBLE_MULTILOCK_H
#define CRUCIBLE_MULTILOCK_H
+#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <deque>
/// Bumped each time a new turn begins; a waiter belongs to the current cohort iff its captured phase is older than this.
uint64_t m_phase = 0;
/// When false, get_lock() returns a null handle and no serialization is performed.
- bool m_do_locking = true;
+ /// Atomic because it may be changed while other threads are taking locks.
+ atomic<bool> m_do_locking{true};
/** \brief Movable-by-shared_ptr token representing one held lock of a given type.
shared_ptr and performs no serialization.
*/
static shared_ptr<LockHandle> get_lock(const string &type);
- /// \brief Globally enable or disable locking on the process-wide instance; when disabled, get_lock() is a no-op returning null.
+ /** \brief Globally enable or disable locking on the process-wide instance; when disabled, get_lock() is a no-op returning null.
+
+ May be called at any time. Disabling does not revoke locks
+ already held or wake threads already waiting: held handles
+ still release normally, and waiters are granted as the
+ current holders drain. Only later get_lock() calls change.
+ */
static void enable_locking(bool enabled);
/** \brief Number of threads currently blocked waiting for a turn of \p type.