SceneSwitcher/lib/utils/sync-helpers.cpp
WarmUpTill 7a0e08b0d8
Some checks are pending
debian-build / build (push) Waiting to run
Push to master / Check Formatting 🔍 (push) Waiting to run
Push to master / Build Project 🧱 (push) Waiting to run
Push to master / Create Release 🛫 (push) Blocked by required conditions
Adapt to enable testing and add more tests
2026-03-14 13:34:50 +01:00

70 lines
1.2 KiB
C++

#include "sync-helpers.hpp"
namespace advss {
#ifdef UNIT_TEST
std::mutex *GetSwitcherMutex()
{
static std::mutex m;
return &m;
}
std::unique_lock<std::mutex> *GetSwitcherLoopLock()
{
static std::mutex m;
static std::unique_lock<std::mutex> lock(m);
return &lock;
}
#else
std::mutex *GetSwitcherMutex();
std::unique_lock<std::mutex> *GetSwitcherLoopLock();
#endif
std::mutex *GetMutex()
{
return GetSwitcherMutex();
}
std::lock_guard<std::mutex> LockContext()
{
return std::lock_guard<std::mutex>(*GetSwitcherMutex());
}
std::unique_lock<std::mutex> *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<std::mutex> Lockable::Lock()
{
return std::lock_guard<std::mutex>(_mtx);
}
void Lockable::WithLock(const std::function<void()> &func)
{
const auto lock = Lock();
func();
}
} // namespace advss