mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
CJob: Even cancel finished jobs
When a job was cancelled after its runThread() method finished, but before the main thread noticed this and reacted, we would just run runMain() before and pretend the job finished normally. However, with CModuleJob this means that runMain() might get called for a module which is currently being destructed. This has bad effects with virtual functions and thus causes problems. It's better to just really cancel the job instead. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
@@ -187,6 +187,7 @@ void CThreadPool::cancelJobs(const std::set<CJob *> &jobs) {
|
||||
continue;
|
||||
|
||||
case CJob::DONE:
|
||||
(*it)->m_eState = CJob::CANCELLED;
|
||||
finished.insert(*it);
|
||||
continue;
|
||||
|
||||
@@ -226,8 +227,11 @@ void CThreadPool::cancelJobs(const std::set<CJob *> &jobs) {
|
||||
// Handle finished jobs. They must already be in the pipe.
|
||||
while (!finished.empty()) {
|
||||
CJob *job = getJobFromPipe();
|
||||
finishJob(job);
|
||||
finished.erase(job);
|
||||
if (finished.erase(job) > 0) {
|
||||
assert(job->m_eState == CJob::CANCELLED);
|
||||
delete job;
|
||||
} else
|
||||
finishJob(job);
|
||||
}
|
||||
|
||||
// Delete things that still need to be deleted
|
||||
|
||||
Reference in New Issue
Block a user