diff options
author | Uwe Klotz <uklotz@mixxx.org> | 2020-05-10 09:13:23 +0200 |
---|---|---|
committer | Uwe Klotz <uklotz@mixxx.org> | 2020-05-10 09:15:02 +0200 |
commit | 05c8275ed428e23dd3ff2048b4fdb615978cfde5 (patch) | |
tree | 670689b35f9dbb80239652fc99b4c9c13e45f555 | |
parent | dcc7b4e273ddecfd77a1971f0936dc355f4f090d (diff) |
Don't let worker threads suspend or stop themselves
-rw-r--r-- | src/util/workerthread.cpp | 14 | ||||
-rw-r--r-- | src/util/workerthread.h | 14 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/util/workerthread.cpp b/src/util/workerthread.cpp index defe74726a..4f570f94c8 100644 --- a/src/util/workerthread.cpp +++ b/src/util/workerthread.cpp @@ -69,6 +69,7 @@ void WorkerThread::run() { } void WorkerThread::suspend() { + DEBUG_ASSERT(QThread::currentThread() != this); logTrace(m_logger, "Suspending"); m_suspend.store(true); // The thread will suspend processing and fall asleep the @@ -77,6 +78,7 @@ void WorkerThread::suspend() { } void WorkerThread::resume() { + DEBUG_ASSERT(QThread::currentThread() != this); logTrace(m_logger, "Resuming"); // Reset m_suspend to false to allow the thread to make progress. m_suspend.store(false); @@ -90,6 +92,7 @@ void WorkerThread::resume() { } void WorkerThread::wake() { + DEBUG_ASSERT(QThread::currentThread() != this); logTrace(m_logger, "Waking up"); std::unique_lock<std::mutex> locked(m_sleepMutex); // We need to always aquire the mutex before notifying the @@ -100,6 +103,7 @@ void WorkerThread::wake() { } void WorkerThread::stop() { + DEBUG_ASSERT(QThread::currentThread() != this); logTrace(m_logger, "Stopping"); m_stop.store(true); // Wake up the thread to make sure that the stop flag is @@ -149,16 +153,6 @@ bool WorkerThread::waitUntilWorkItemsFetched() { m_sleepWaitCond.wait(locked) ; logTrace(m_logger, "Continuing after slept while idle"); break; - case FetchWorkResult::Suspend: - logTrace(m_logger, "Suspending while idle"); - suspend(); - sleepWhileSuspended(&locked); - logTrace(m_logger, "Continuing after suspended while idle"); - break; - case FetchWorkResult::Stop: - logTrace(m_logger, "Stopping after trying to fetch work items"); - stop(); - break; } } return false; diff --git a/src/util/workerthread.h b/src/util/workerthread.h index 5d9a1140ad..07e6a6f9c8 100644 --- a/src/util/workerthread.h +++ b/src/util/workerthread.h @@ -45,18 +45,30 @@ class WorkerThread : public QThread { } /// Commands the thread to suspend itself asap. + /// + /// Must not be invoked from the worker thread itself to + /// avoid race conditions! void suspend(); /// Resumes a suspended thread by waking it up. + /// + /// Must not be invoked from the worker thread itself to + /// avoid race conditions! void resume(); /// Wakes up a sleeping thread. If the thread has been suspended /// it will fall asleep again. A suspended thread needs to be /// resumed. + /// + /// Must not be invoked from the worker thread itself to + /// avoid race conditions! void wake(); /// Commands the thread to stop asap. This action is irreversible, /// i.e. the thread cannot be restarted once it has been stopped. + /// + /// Must not be invoked from the worker thread itself to + /// avoid race conditions! void stop(); /// Non-blocking atomic read of the stop flag which indicates that @@ -81,8 +93,6 @@ class WorkerThread : public QThread { enum class FetchWorkResult { Ready, Idle, - Suspend, - Stop, }; /// Non-blocking function that determines whether the worker thread |