Skip to content

Commit

Permalink
Merge pull request #44732 from Calinou/os-add-get-thread-caller-id
Browse files Browse the repository at this point in the history
Add an `OS.get_thread_caller_id()` method
  • Loading branch information
akien-mga authored Jan 26, 2021
2 parents 34eb563 + 35b046d commit d6765c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,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);
}
Expand Down Expand Up @@ -764,6 +768,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);

Expand Down
1 change: 1 addition & 0 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class _OS : public Object {
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;

Expand Down
8 changes: 8 additions & 0 deletions doc/classes/OS.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,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>
Expand Down

0 comments on commit d6765c8

Please sign in to comment.