mirror of
https://github.com/Relintai/thread_pool.git
synced 2024-11-12 10:25:29 +01:00
Check whether a job is cancelled in ThreadPool's update(). Also Improved the logic of the worker thread func a bit.
This commit is contained in:
parent
c401b7a027
commit
1e2a611ebd
@ -233,8 +233,15 @@ void ThreadPool::_worker_thread_func(void *user_data) {
|
||||
while (context->running) {
|
||||
context->semaphore->wait();
|
||||
|
||||
if (!context->job.is_valid())
|
||||
if (!context->job.is_valid()) {
|
||||
ThreadPool::get_singleton()->_thread_finished(context);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (context->job->get_cancelled()) {
|
||||
ThreadPool::get_singleton()->_thread_finished(context);
|
||||
continue;
|
||||
}
|
||||
|
||||
context->job->execute();
|
||||
|
||||
@ -265,7 +272,7 @@ void ThreadPool::update() {
|
||||
|
||||
remaining_time -= job->get_current_execution_time();
|
||||
|
||||
if (job->get_complete()) {
|
||||
if (job->get_complete() || job->get_cancelled()) {
|
||||
_queue.write[_current_queue_head++].unref();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user