Internals: Rename and slightly change other threads stopping/resuming methods. (#4478)

Co-authored-by: Mariusz Glebocki <mglebocki@antmicro.com>
This commit is contained in:
Kamil Rakoczy 2023-09-11 19:43:26 +02:00 committed by GitHub
parent e77d847671
commit 5676443139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 12 deletions

View File

@ -84,11 +84,11 @@ void V3ThreadPool::workerJobLoop(int id) VL_MT_SAFE {
bool V3ThreadPool::waitIfStopRequested() VL_MT_SAFE VL_EXCLUDES(m_stoppedJobsMutex) {
if (!stopRequested()) return false;
V3LockGuard stoppedJobLock(m_stoppedJobsMutex);
waitStopRequested();
waitForResumeRequest();
return true;
}
void V3ThreadPool::waitStopRequested() VL_REQUIRES(m_stoppedJobsMutex) {
void V3ThreadPool::waitForResumeRequest() VL_REQUIRES(m_stoppedJobsMutex) {
++m_stoppedJobs;
m_stoppedJobsCV.notify_all();
m_stoppedJobsCV.wait(m_stoppedJobsMutex, [&]() VL_REQUIRES(m_stoppedJobsMutex) {
@ -98,8 +98,9 @@ void V3ThreadPool::waitStopRequested() VL_REQUIRES(m_stoppedJobsMutex) {
m_stoppedJobsCV.notify_all();
}
void V3ThreadPool::waitOtherThreads() VL_MT_SAFE_EXCLUDES(m_mutex)
void V3ThreadPool::stopOtherThreads() VL_MT_SAFE_EXCLUDES(m_mutex)
VL_REQUIRES(m_stoppedJobsMutex) {
m_stopRequested = true;
++m_stoppedJobs;
m_stoppedJobsCV.notify_all();
m_cv.notify_all();

View File

@ -192,11 +192,17 @@ private:
return m_stopRequested;
}
// Waits until exclusive access job completes its job
void waitStopRequested() VL_REQUIRES(m_stoppedJobsMutex);
// Waits until `resumeOtherThreads()` is called or exclusive access scope end.
void waitForResumeRequest() VL_REQUIRES(m_stoppedJobsMutex);
// Waits until all other jobs are stopped
void waitOtherThreads() VL_MT_SAFE_EXCLUDES(m_mutex) VL_REQUIRES(m_stoppedJobsMutex);
// Sends stop request to other threads and waits until they stop.
void stopOtherThreads() VL_MT_SAFE_EXCLUDES(m_mutex) VL_REQUIRES(m_stoppedJobsMutex);
// Resumes threads stopped through previous call to `stopOtherThreads()`.
void resumeOtherThreads() VL_MT_SAFE_EXCLUDES(m_mutex) VL_REQUIRES(m_stoppedJobsMutex) {
m_stopRequested = false;
m_stoppedJobsCV.notify_all();
}
void workerJobLoop(int id) VL_MT_SAFE;
@ -209,9 +215,8 @@ public:
if (!V3ThreadPool::s().willExecuteSynchronously()) {
V3ThreadPool::s().m_stoppedJobsMutex.lock();
if (V3ThreadPool::s().stopRequested()) { V3ThreadPool::s().waitStopRequested(); }
V3ThreadPool::s().m_stopRequested = true;
V3ThreadPool::s().waitOtherThreads();
if (V3ThreadPool::s().stopRequested()) { V3ThreadPool::s().waitForResumeRequest(); }
V3ThreadPool::s().stopOtherThreads();
V3ThreadPool::s().m_exclusiveAccess = true;
} else {
V3ThreadPool::s().m_stoppedJobsMutex.assumeLocked();
@ -221,8 +226,7 @@ public:
// Can't use `willExecuteSynchronously`, we're still in exclusive execution state.
if (V3ThreadPool::s().m_exclusiveAccess) {
V3ThreadPool::s().m_exclusiveAccess = false;
V3ThreadPool::s().m_stopRequested = false;
V3ThreadPool::s().m_stoppedJobsCV.notify_all();
V3ThreadPool::s().resumeOtherThreads();
V3ThreadPool::s().m_stoppedJobsMutex.unlock();
} else {