소스 검색

Merge pull request #54932 from briansemrau/expose-main-thread-id

Rémi Verschelde 3 년 전
부모
커밋
be16eb625b
3개의 변경된 파일13개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      core/core_bind.cpp
  2. 1 0
      core/core_bind.h
  3. 7 0
      doc/classes/OS.xml

+ 5 - 0
core/core_bind.cpp

@@ -315,6 +315,10 @@ Error OS::set_thread_name(const String &p_name) {
 	return ::Thread::get_caller_id();
 };
 
+::Thread::ID OS::get_main_thread_id() const {
+	return ::Thread::get_main_id();
+};
+
 bool OS::has_feature(const String &p_feature) const {
 	return ::OS::get_singleton()->has_feature(p_feature);
 }
@@ -601,6 +605,7 @@ void OS::_bind_methods() {
 
 	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("get_main_thread_id"), &OS::get_main_thread_id);
 
 	ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &OS::has_feature);
 

+ 1 - 0
core/core_bind.h

@@ -237,6 +237,7 @@ public:
 
 	Error set_thread_name(const String &p_name);
 	Thread::ID get_thread_caller_id() const;
+	Thread::ID get_main_thread_id() const;
 
 	bool has_feature(const String &p_feature) const;
 

+ 7 - 0
doc/classes/OS.xml

@@ -246,6 +246,13 @@
 				This can be used to narrow down fully specified locale strings to only the "common" language code, when you don't need the additional information about country code or variants. For example, for a French Canadian user with [code]fr_CA[/code] locale, this would return [code]fr[/code].
 			</description>
 		</method>
+		<method name="get_main_thread_id" qualifiers="const">
+			<return type="int" />
+			<description>
+				Returns the ID of the main thread. See [method get_thread_caller_id].
+				[b]Note:[/b] Thread IDs are not deterministic and may be reused across application restarts.
+			</description>
+		</method>
 		<method name="get_model_name" qualifiers="const">
 			<return type="String" />
 			<description>