mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Don't polling to wait the exit of threads in CThreadPool destructor
All values are protected by m_mutex. So we don't need the polling to wait m_num_threads==0 with wakeups, instead simply use CConditionVariable.
This commit is contained in:
@@ -84,15 +84,12 @@ void CThreadPool::finishJob(CJob *job) const {
|
||||
}
|
||||
|
||||
CThreadPool::~CThreadPool() {
|
||||
/* Anyone has an idea how this can be done less ugly? */
|
||||
CMutexLocker guard(m_mutex);
|
||||
m_done = true;
|
||||
|
||||
while (m_num_threads > 0) {
|
||||
if (m_num_threads > 0) {
|
||||
m_cond.broadcast();
|
||||
guard.unlock();
|
||||
usleep(100);
|
||||
guard.lock();
|
||||
m_exit_cond.wait(m_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +131,9 @@ void CThreadPool::threadFunc() {
|
||||
assert(m_num_threads > 0 && m_num_idle > 0);
|
||||
m_num_threads--;
|
||||
m_num_idle--;
|
||||
|
||||
if (m_num_threads == 0 && m_done)
|
||||
m_exit_cond.signal();
|
||||
}
|
||||
|
||||
void CThreadPool::addJob(CJob *job) {
|
||||
|
||||
Reference in New Issue
Block a user