mirror of
https://github.com/verilator/verilator.git
synced 2025-02-07 22:21:52 +00:00
Internals: Rename and slightly change other threads stopping/resuming methods. (#4478)
Co-authored-by: Mariusz Glebocki <mglebocki@antmicro.com>
This commit is contained in:
parent
e77d847671
commit
5676443139
@ -84,11 +84,11 @@ void V3ThreadPool::workerJobLoop(int id) VL_MT_SAFE {
|
|||||||
bool V3ThreadPool::waitIfStopRequested() VL_MT_SAFE VL_EXCLUDES(m_stoppedJobsMutex) {
|
bool V3ThreadPool::waitIfStopRequested() VL_MT_SAFE VL_EXCLUDES(m_stoppedJobsMutex) {
|
||||||
if (!stopRequested()) return false;
|
if (!stopRequested()) return false;
|
||||||
V3LockGuard stoppedJobLock(m_stoppedJobsMutex);
|
V3LockGuard stoppedJobLock(m_stoppedJobsMutex);
|
||||||
waitStopRequested();
|
waitForResumeRequest();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void V3ThreadPool::waitStopRequested() VL_REQUIRES(m_stoppedJobsMutex) {
|
void V3ThreadPool::waitForResumeRequest() VL_REQUIRES(m_stoppedJobsMutex) {
|
||||||
++m_stoppedJobs;
|
++m_stoppedJobs;
|
||||||
m_stoppedJobsCV.notify_all();
|
m_stoppedJobsCV.notify_all();
|
||||||
m_stoppedJobsCV.wait(m_stoppedJobsMutex, [&]() VL_REQUIRES(m_stoppedJobsMutex) {
|
m_stoppedJobsCV.wait(m_stoppedJobsMutex, [&]() VL_REQUIRES(m_stoppedJobsMutex) {
|
||||||
@ -98,8 +98,9 @@ void V3ThreadPool::waitStopRequested() VL_REQUIRES(m_stoppedJobsMutex) {
|
|||||||
m_stoppedJobsCV.notify_all();
|
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) {
|
VL_REQUIRES(m_stoppedJobsMutex) {
|
||||||
|
m_stopRequested = true;
|
||||||
++m_stoppedJobs;
|
++m_stoppedJobs;
|
||||||
m_stoppedJobsCV.notify_all();
|
m_stoppedJobsCV.notify_all();
|
||||||
m_cv.notify_all();
|
m_cv.notify_all();
|
||||||
|
@ -192,11 +192,17 @@ private:
|
|||||||
return m_stopRequested;
|
return m_stopRequested;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Waits until exclusive access job completes its job
|
// Waits until `resumeOtherThreads()` is called or exclusive access scope end.
|
||||||
void waitStopRequested() VL_REQUIRES(m_stoppedJobsMutex);
|
void waitForResumeRequest() VL_REQUIRES(m_stoppedJobsMutex);
|
||||||
|
|
||||||
// Waits until all other jobs are stopped
|
// Sends stop request to other threads and waits until they stop.
|
||||||
void waitOtherThreads() VL_MT_SAFE_EXCLUDES(m_mutex) VL_REQUIRES(m_stoppedJobsMutex);
|
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;
|
void workerJobLoop(int id) VL_MT_SAFE;
|
||||||
|
|
||||||
@ -209,9 +215,8 @@ public:
|
|||||||
if (!V3ThreadPool::s().willExecuteSynchronously()) {
|
if (!V3ThreadPool::s().willExecuteSynchronously()) {
|
||||||
V3ThreadPool::s().m_stoppedJobsMutex.lock();
|
V3ThreadPool::s().m_stoppedJobsMutex.lock();
|
||||||
|
|
||||||
if (V3ThreadPool::s().stopRequested()) { V3ThreadPool::s().waitStopRequested(); }
|
if (V3ThreadPool::s().stopRequested()) { V3ThreadPool::s().waitForResumeRequest(); }
|
||||||
V3ThreadPool::s().m_stopRequested = true;
|
V3ThreadPool::s().stopOtherThreads();
|
||||||
V3ThreadPool::s().waitOtherThreads();
|
|
||||||
V3ThreadPool::s().m_exclusiveAccess = true;
|
V3ThreadPool::s().m_exclusiveAccess = true;
|
||||||
} else {
|
} else {
|
||||||
V3ThreadPool::s().m_stoppedJobsMutex.assumeLocked();
|
V3ThreadPool::s().m_stoppedJobsMutex.assumeLocked();
|
||||||
@ -221,8 +226,7 @@ public:
|
|||||||
// Can't use `willExecuteSynchronously`, we're still in exclusive execution state.
|
// Can't use `willExecuteSynchronously`, we're still in exclusive execution state.
|
||||||
if (V3ThreadPool::s().m_exclusiveAccess) {
|
if (V3ThreadPool::s().m_exclusiveAccess) {
|
||||||
V3ThreadPool::s().m_exclusiveAccess = false;
|
V3ThreadPool::s().m_exclusiveAccess = false;
|
||||||
V3ThreadPool::s().m_stopRequested = false;
|
V3ThreadPool::s().resumeOtherThreads();
|
||||||
V3ThreadPool::s().m_stoppedJobsCV.notify_all();
|
|
||||||
|
|
||||||
V3ThreadPool::s().m_stoppedJobsMutex.unlock();
|
V3ThreadPool::s().m_stoppedJobsMutex.unlock();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user