Fix crash when stopping queue from within the queue

This commit is contained in:
WarmUpTill 2024-03-28 20:53:07 +01:00 committed by WarmUpTill
parent 6b4bcc074a
commit 96db0ad507
2 changed files with 11 additions and 3 deletions

View File

@ -51,9 +51,13 @@ void ActionQueue::Load(obs_data_t *obj)
void ActionQueue::Start()
{
if (_thread.joinable()) {
if (!_stop) {
return;
}
if (_thread.joinable()) {
_thread.join();
}
_stop = false;
_thread = std::thread(&ActionQueue::RunActions, this);
}
@ -62,6 +66,10 @@ void ActionQueue::Stop()
{
_stop = true;
_cv.notify_all();
if (std::this_thread::get_id() == _thread.get_id()) {
return;
}
if (_thread.joinable()) {
_thread.join();
}
@ -69,7 +77,7 @@ void ActionQueue::Stop()
bool ActionQueue::IsRunning() const
{
return _thread.joinable();
return !_stop;
}
bool ActionQueue::RunsOnStartup() const

View File

@ -39,7 +39,7 @@ private:
bool _runOnStartup = true;
bool _resolveVariablesOnAdd = true;
std::atomic_bool _stop = {false};
std::atomic_bool _stop = {true};
std::mutex _mutex;
std::condition_variable _cv;
std::thread _thread;