mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
This should avoid crashes when actions or conditions are performed in parallel to the main macro loop and will improve the UI responsiveness in some scenarios
56 lines
963 B
C++
56 lines
963 B
C++
#include "sync-helpers.hpp"
|
|
|
|
namespace advss {
|
|
|
|
std::mutex *GetSwitcherMutex();
|
|
std::unique_lock<std::mutex> *GetSwitcherLoopLock();
|
|
|
|
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
|