Skip to content

Commit 8862d4c

Browse files
committed
Merge pull request godotengine#107029 from mhilbrunner/expose-workerthreadpool-gettaskid
Expose `WorkerThreadPool.get_caller_task_id()`
2 parents e5c8fb8 + 7ef1cf3 commit 8862d4c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

core/object/worker_thread_pool.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,8 @@ void WorkerThreadPool::_bind_methods() {
861861
ClassDB::bind_method(D_METHOD("is_group_task_completed", "group_id"), &WorkerThreadPool::is_group_task_completed);
862862
ClassDB::bind_method(D_METHOD("get_group_processed_element_count", "group_id"), &WorkerThreadPool::get_group_processed_element_count);
863863
ClassDB::bind_method(D_METHOD("wait_for_group_task_completion", "group_id"), &WorkerThreadPool::wait_for_group_task_completion);
864+
865+
ClassDB::bind_method(D_METHOD("get_caller_task_id"), &WorkerThreadPool::get_caller_task_id);
864866
}
865867

866868
WorkerThreadPool *WorkerThreadPool::get_named_pool(const StringName &p_name) {

doc/classes/WorkerThreadPool.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@
7272
[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.
7373
</description>
7474
</method>
75+
<method name="get_caller_task_id" qualifiers="const">
76+
<return type="int" />
77+
<description>
78+
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).
79+
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.
80+
[b]Note:[/b] Group tasks have their own IDs, so this method will return [code]-1[/code] for group tasks.
81+
</description>
82+
</method>
7583
<method name="get_group_processed_element_count" qualifiers="const">
7684
<return type="int" />
7785
<param index="0" name="group_id" type="int" />

0 commit comments

Comments
 (0)