summaryrefslogtreecommitdiffstats
path: root/core/object
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2024-09-10 11:08:51 +0200
committerPedro J. Estébanez <pedrojrulez@gmail.com>2024-09-10 11:08:51 +0200
commit2d1dd41ef5dcb51ddb607ba572e63b605b9191be (patch)
tree345b1d6ca7786cb36a72badfcdfd50e4afc11bcb /core/object
parentd0dc3896ad6fe039e4ad0607d901c81197cb3a3b (diff)
downloadredot-engine-2d1dd41ef5dcb51ddb607ba572e63b605b9191be.tar.gz
WorkerThreadPool: Enhance lifetime for more flexibility
Diffstat (limited to 'core/object')
-rw-r--r--core/object/worker_thread_pool.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp
index fe7bbd474c..da503966b1 100644
--- a/core/object/worker_thread_pool.cpp
+++ b/core/object/worker_thread_pool.cpp
@@ -326,6 +326,8 @@ WorkerThreadPool::TaskID WorkerThreadPool::add_native_task(void (*p_func)(void *
}
WorkerThreadPool::TaskID WorkerThreadPool::_add_task(const Callable &p_callable, void (*p_func)(void *), void *p_userdata, BaseTemplateUserdata *p_template_userdata, bool p_high_priority, const String &p_description) {
+ ERR_FAIL_COND_V_MSG(threads.is_empty(), INVALID_TASK_ID, "Can't add a task because the WorkerThreadPool is either not initialized yet or already terminated.");
+
task_mutex.lock();
// Get a free task
Task *task = task_allocator.alloc();
@@ -538,6 +540,7 @@ void WorkerThreadPool::notify_yield_over(TaskID p_task_id) {
}
WorkerThreadPool::GroupID WorkerThreadPool::_add_group_task(const Callable &p_callable, void (*p_func)(void *, uint32_t), void *p_userdata, BaseTemplateUserdata *p_template_userdata, int p_elements, int p_tasks, bool p_high_priority, const String &p_description) {
+ ERR_FAIL_COND_V_MSG(threads.is_empty(), INVALID_TASK_ID, "Can't add a group task because the WorkerThreadPool is either not initialized yet or already terminated.");
ERR_FAIL_COND_V(p_elements < 0, INVALID_TASK_ID);
if (p_tasks < 0) {
p_tasks = MAX(1u, threads.size());
@@ -749,5 +752,5 @@ WorkerThreadPool::WorkerThreadPool() {
}
WorkerThreadPool::~WorkerThreadPool() {
- finish();
+ DEV_ASSERT(threads.size() == 0 && "finish() hasn't been called!");
}