Expose WorkerThreadPool.get_caller_task_id()

This commit is contained in:
Max Hilbrunner 2025-06-01 22:30:29 +02:00
parent 64b09905c7
commit 7ef1cf3c2e
2 changed files with 10 additions and 0 deletions

View File

@ -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) {

View File

@ -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.
</description>
</method>
<method name="get_caller_task_id" qualifiers="const">
<return type="int" />
<description>
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.
</description>
</method>
<method name="get_group_processed_element_count" qualifiers="const">
<return type="int" />
<param index="0" name="group_id" type="int" />