summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2020-12-27 16:49:46 +0100
committerHugo Locurcio <hugo.locurcio@hugo.pro>2020-12-27 16:54:18 +0100
commit35b046ddf7eab341256cced9d1c77e168c52e256 (patch)
tree801378798192580673fbd225f54c8ab6693b5545
parentd55e335026e4848d4d2ec21db8f334a9429c8cc8 (diff)
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>
-rw-r--r--core/core_bind.cpp5
-rw-r--r--core/core_bind.h1
-rw-r--r--doc/classes/OS.xml8
3 files changed, 14 insertions, 0 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 259d899d39..b06396230f 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -290,6 +290,10 @@ Error _OS::set_thread_name(const String &p_name) {
return Thread::set_name(p_name);
}
+Thread::ID _OS::get_thread_caller_id() const {
+ return Thread::get_caller_id();
+};
+
bool _OS::has_feature(const String &p_feature) const {
return OS::get_singleton()->has_feature(p_feature);
}
@@ -758,6 +762,7 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_use_file_access_save_and_swap", "enabled"), &_OS::set_use_file_access_save_and_swap);
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("has_feature", "tag_name"), &_OS::has_feature);
diff --git a/core/core_bind.h b/core/core_bind.h
index f3a77a4fa6..ce4ab1d5fb 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -232,6 +232,7 @@ public:
String get_user_data_dir() const;
Error set_thread_name(const String &p_name);
+ Thread::ID get_thread_caller_id() const;
bool has_feature(const String &p_feature) const;
diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml
index 65a815a603..f72590f62f 100644
--- a/doc/classes/OS.xml
+++ b/doc/classes/OS.xml
@@ -127,6 +127,14 @@
Returns the keycode of the given string (e.g. "Escape").
</description>
</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_cmdline_args">
<return type="PackedStringArray">
</return>