mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-08 02:07:20 -05:00
The previous approach had the problem of losing any action internal state changes in the created copy. Revert "Fix temp var values of actions not being accessible" This reverts commitdf42538319. Revert "Don't block UI while running actions" This reverts commita01d26e25d.
81 lines
1.3 KiB
C++
81 lines
1.3 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();
|
|
}
|
|
|
|
SuspendLock::SuspendLock(Lockable &lockable)
|
|
: _mtx(static_cast<std::mutex &>(lockable._mtx))
|
|
{
|
|
_mtx.unlock();
|
|
}
|
|
|
|
SuspendLock::~SuspendLock()
|
|
{
|
|
_mtx.lock();
|
|
}
|
|
|
|
} // namespace advss
|