Internals: Avoid pessimistic mutex locking in waitIfStopRequested() (#4272). No functional change intended.

`stopRequested()` reads only atomic variables. It doesn't need a mutex
to do this.

This function is called in `waitIfStopRequested()`, which in turn
is called before execution of every job, and inside some jobs. With this
change the mutex inside `waitIfStopRequested` needs to be locked only in
very rare cases instead of every time.
This commit is contained in:
Mariusz Glebocki
2023-06-05 19:40:36 -04:00
committed by GitHub
parent 5aa36357f6
commit 186c851695
2 changed files with 5 additions and 10 deletions
+3 -3
View File
@@ -68,7 +68,7 @@ void V3ThreadPool::workerJobLoop(int id) VL_MT_SAFE {
return !m_queue.empty() || m_shutdown || m_stopRequested;
});
if (m_shutdown) return; // Terminate if requested
if (stopRequestedStandalone()) { continue; }
if (stopRequested()) { continue; }
// Get the job
UASSERT(!m_queue.empty(), "Job should be available");
@@ -115,9 +115,9 @@ void V3ThreadPool::requestExclusiveAccess(const V3ThreadPool::job_t&& exclusiveA
}
}
bool V3ThreadPool::waitIfStopRequested() VL_MT_SAFE {
V3LockGuard stoppedJobLock(m_stoppedJobsMutex);
bool V3ThreadPool::waitIfStopRequested() VL_MT_SAFE VL_EXCLUDES(m_stoppedJobsMutex) {
if (!stopRequested()) return false;
V3LockGuard stoppedJobLock(m_stoppedJobsMutex);
waitStopRequested();
return true;
}