Refactor locking of macro segments

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
This commit is contained in:
WarmUpTill
2025-06-16 21:55:17 +02:00
committed by WarmUpTill
parent 98d1f83acc
commit 874b9b86e2
7 changed files with 107 additions and 19 deletions

View File

@@ -20,4 +20,36 @@ 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