Expose Thread::is_main_thread()

This commit is contained in:
David Snopek 2025-08-19 10:35:45 -05:00
parent 8ebf8ae23c
commit b9bff1fba5
3 changed files with 13 additions and 0 deletions

View file

@ -1526,6 +1526,10 @@ void Thread::set_thread_safety_checks_enabled(bool p_enabled) {
set_current_thread_safe_for_nodes(!p_enabled);
}
bool Thread::is_main_thread() {
return ::Thread::is_main_thread();
}
void Thread::_bind_methods() {
ClassDB::bind_method(D_METHOD("start", "callable", "priority"), &Thread::start, DEFVAL(PRIORITY_NORMAL));
ClassDB::bind_method(D_METHOD("get_id"), &Thread::get_id);
@ -1534,6 +1538,7 @@ void Thread::_bind_methods() {
ClassDB::bind_method(D_METHOD("wait_to_finish"), &Thread::wait_to_finish);
ClassDB::bind_static_method("Thread", D_METHOD("set_thread_safety_checks_enabled", "enabled"), &Thread::set_thread_safety_checks_enabled);
ClassDB::bind_static_method("Thread", D_METHOD("is_main_thread"), &Thread::is_main_thread);
BIND_ENUM_CONSTANT(PRIORITY_LOW);
BIND_ENUM_CONSTANT(PRIORITY_NORMAL);

View file

@ -495,6 +495,7 @@ public:
Variant wait_to_finish();
static void set_thread_safety_checks_enabled(bool p_enabled);
static bool is_main_thread();
};
namespace Special {

View file

@ -30,6 +30,13 @@
To check if a [Thread] is joinable, use [method is_started].
</description>
</method>
<method name="is_main_thread" qualifiers="static">
<return type="bool" />
<description>
Returns [code]true[/code] if the thread this method was called from is the main thread.
[b]Note:[/b] This is a static method and isn't associated with a specific [Thread] object.
</description>
</method>
<method name="is_started" qualifiers="const">
<return type="bool" />
<description>