mirror of
https://github.com/verilator/verilator.git
synced 2026-09-04 00:30:34 +02:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user