From 9a2a39923a101cde6265add9bf280f2f2f90911f Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 5 Jun 2023 09:05:16 +0200 Subject: [PATCH] Added virtual _execute to threadPoolJob. --- core/os/thread_pool_job.cpp | 15 +++++++++++---- core/os/thread_pool_job.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/os/thread_pool_job.cpp b/core/os/thread_pool_job.cpp index 552b16255..25b96e9a5 100644 --- a/core/os/thread_pool_job.cpp +++ b/core/os/thread_pool_job.cpp @@ -107,18 +107,18 @@ bool ThreadPoolJob::should_do(const bool just_check) { return true; } bool ThreadPoolJob::should_return() { - if (_cancelled) + if (_cancelled) { return true; + } - if (_max_allocated_time < 0.00001) + if (_max_allocated_time < 0.00001) { return false; + } return get_current_execution_time() >= _max_allocated_time; } void ThreadPoolJob::execute() { - ERR_FAIL_COND(!has_method("_execute")); - _current_run_stage = 0; _start_time = OS::get_singleton()->get_system_time_msecs(); @@ -126,6 +126,12 @@ void ThreadPoolJob::execute() { call("_execute"); } +void ThreadPoolJob::_execute() { + set_complete(true); + + ERR_FAIL_MSG(get_class() + " ThreadPoolJob::_execute is not overridden!"); +} + ThreadPoolJob::ThreadPoolJob() { _complete = true; _cancelled = false; @@ -181,6 +187,7 @@ void ThreadPoolJob::_bind_methods() { BIND_VMETHOD(MethodInfo("_execute")); ClassDB::bind_method(D_METHOD("execute"), &ThreadPoolJob::execute); + ClassDB::bind_method(D_METHOD("_execute"), &ThreadPoolJob::_execute); ADD_SIGNAL(MethodInfo("completed")); } diff --git a/core/os/thread_pool_job.h b/core/os/thread_pool_job.h index dba34225d..b2cdcf277 100644 --- a/core/os/thread_pool_job.h +++ b/core/os/thread_pool_job.h @@ -63,6 +63,7 @@ public: bool should_return(); void execute(); + virtual void _execute(); ThreadPoolJob(); ~ThreadPoolJob();