From 7ef1cf3c2ee911d12855288fe92bb63b73c93951 Mon Sep 17 00:00:00 2001 From: Max Hilbrunner Date: Sun, 1 Jun 2025 22:30:29 +0200 Subject: [PATCH] Expose WorkerThreadPool.get_caller_task_id() --- core/object/worker_thread_pool.cpp | 2 ++ doc/classes/WorkerThreadPool.xml | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp index 2d4f476d07b..5ffb4e979bc 100644 --- a/core/object/worker_thread_pool.cpp +++ b/core/object/worker_thread_pool.cpp @@ -861,6 +861,8 @@ void WorkerThreadPool::_bind_methods() { ClassDB::bind_method(D_METHOD("is_group_task_completed", "group_id"), &WorkerThreadPool::is_group_task_completed); ClassDB::bind_method(D_METHOD("get_group_processed_element_count", "group_id"), &WorkerThreadPool::get_group_processed_element_count); ClassDB::bind_method(D_METHOD("wait_for_group_task_completion", "group_id"), &WorkerThreadPool::wait_for_group_task_completion); + + ClassDB::bind_method(D_METHOD("get_caller_task_id"), &WorkerThreadPool::get_caller_task_id); } WorkerThreadPool *WorkerThreadPool::get_named_pool(const StringName &p_name) { diff --git a/doc/classes/WorkerThreadPool.xml b/doc/classes/WorkerThreadPool.xml index 2b1bc136cbb..06618a46318 100644 --- a/doc/classes/WorkerThreadPool.xml +++ b/doc/classes/WorkerThreadPool.xml @@ -72,6 +72,14 @@ [b]Warning:[/b] Every task must be waited for completion using [method wait_for_task_completion] or [method wait_for_group_task_completion] at some point so that any allocated resources inside the task can be cleaned up. + + + + Returns the task ID of the current thread calling this method, or [code]-1[/code] if the task is a group task, invalid or the current thread is not part of the thread pool (e.g. the main thread). + Can be used by a task to get its own task ID, or to determine whether the current code is running inside the worker thread pool. + [b]Note:[/b] Group tasks have their own IDs, so this method will return [code]-1[/code] for group tasks. + +