#include "sync-helpers.hpp" namespace advss { #ifdef UNIT_TEST std::mutex *GetSwitcherMutex() { static std::mutex m; return &m; } std::unique_lock *GetSwitcherLoopLock() { static std::mutex m; static std::unique_lock lock(m); return &lock; } #else std::mutex *GetSwitcherMutex(); std::unique_lock *GetSwitcherLoopLock(); #endif std::mutex *GetMutex() { return GetSwitcherMutex(); } std::lock_guard LockContext() { return std::lock_guard(*GetSwitcherMutex()); } std::unique_lock *GetLoopLock() { return GetSwitcherLoopLock(); } PerInstanceMutex::PerInstanceMutex() {} PerInstanceMutex::~PerInstanceMutex(){}; PerInstanceMutex::PerInstanceMutex(const PerInstanceMutex &) {} PerInstanceMutex &PerInstanceMutex::operator=(const PerInstanceMutex &) { return *this; } PerInstanceMutex::operator std::mutex &() { return _mtx; } PerInstanceMutex::operator const std::mutex &() const { return _mtx; } std::lock_guard Lockable::Lock() { return std::lock_guard(_mtx); } void Lockable::WithLock(const std::function &func) { const auto lock = Lock(); func(); } } // namespace advss