Add an `OS.get_thread_caller_id()` method

This can be used to print thread IDs in logs. This can make it easier
to debug multi-threaded applications.

Co-authored-by: Khaos <khaos@khaos-coders.org>
(cherry picked from commit 35b046ddf7)
This commit is contained in:
Hugo Locurcio 2020-12-27 16:49:46 +01:00 committed by Rémi Verschelde
parent 1c9ee4baa2
commit eb0ca31ac1
No known key found for this signature in database
GPG Key ID: C3336907360768E1
3 changed files with 14 additions and 0 deletions

View File

@ -647,6 +647,10 @@ int _OS::get_power_percent_left() {
return OS::get_singleton()->get_power_percent_left(); return OS::get_singleton()->get_power_percent_left();
} }
Thread::ID _OS::get_thread_caller_id() const {
return Thread::get_caller_id();
};
bool _OS::has_feature(const String &p_feature) const { bool _OS::has_feature(const String &p_feature) const {
return OS::get_singleton()->has_feature(p_feature); return OS::get_singleton()->has_feature(p_feature);
@ -1416,6 +1420,7 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("alert", "text", "title"), &_OS::alert, DEFVAL("Alert!")); ClassDB::bind_method(D_METHOD("alert", "text", "title"), &_OS::alert, DEFVAL("Alert!"));
ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &_OS::set_thread_name); ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &_OS::set_thread_name);
ClassDB::bind_method(D_METHOD("get_thread_caller_id"), &_OS::get_thread_caller_id);
ClassDB::bind_method(D_METHOD("set_use_vsync", "enable"), &_OS::set_use_vsync); ClassDB::bind_method(D_METHOD("set_use_vsync", "enable"), &_OS::set_use_vsync);
ClassDB::bind_method(D_METHOD("is_vsync_enabled"), &_OS::is_vsync_enabled); ClassDB::bind_method(D_METHOD("is_vsync_enabled"), &_OS::is_vsync_enabled);

View File

@ -360,6 +360,7 @@ public:
bool is_ok_left_and_cancel_right() const; bool is_ok_left_and_cancel_right() const;
Error set_thread_name(const String &p_name); Error set_thread_name(const String &p_name);
Thread::ID get_thread_caller_id() const;
void set_use_vsync(bool p_enable); void set_use_vsync(bool p_enable);
bool is_vsync_enabled() const; bool is_vsync_enabled() const;

View File

@ -486,6 +486,14 @@
[b]Note:[/b] This method is implemented on Windows. [b]Note:[/b] This method is implemented on Windows.
</description> </description>
</method> </method>
<method name="get_thread_caller_id" qualifiers="const">
<return type="int">
</return>
<description>
Returns the ID of the current thread. This can be used in logs to ease debugging of multi-threaded applications.
[b]Note:[/b] Thread IDs are not deterministic and may be reused across application restarts.
</description>
</method>
<method name="get_ticks_msec" qualifiers="const"> <method name="get_ticks_msec" qualifiers="const">
<return type="int"> <return type="int">
</return> </return>