diff options
author | Juan Linietsky <reduzio@gmail.com> | 2023-04-22 15:34:16 +0200 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2023-04-24 15:13:58 +0200 |
commit | a37c30dfc92d98d79c4a315c58ecb5b2adabf97a (patch) | |
tree | c0a91be57bf01b77c5b0aa090233c63f9135eab1 /main | |
parent | 24cb43a8741c7b10abbbbc77bb6e2bc188662ce0 (diff) | |
download | redot-engine-a37c30dfc92d98d79c4a315c58ecb5b2adabf97a.tar.gz |
Fix thread IDs.
On Linux, thread IDs were not properly assigned with the current approach.
The line:
`std::thread new_thread(&Thread::callback, _thread_id_hash(thread.get_id()), p_settings, p_callback, p_user);`
does not work because the thread ID is not assigned until the thread starts.
This PR changes the behavior to use manually generated thread IDs. Additionally, if a thread is (or may have been created) outside Godot, the method `Thread::attach_external_thread` was added.
Diffstat (limited to 'main')
-rw-r--r-- | main/main.cpp | 14 | ||||
-rw-r--r-- | main/main.h | 2 |
2 files changed, 10 insertions, 6 deletions
diff --git a/main/main.cpp b/main/main.cpp index bc309219f4..6b89d96147 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -471,6 +471,8 @@ void Main::print_help(const char *p_binary) { // The order is the same as in `Main::setup()`, only core and some editor types // are initialized here. This also combines `Main::setup2()` initialization. Error Main::test_setup() { + Thread::make_main_thread(); + OS::get_singleton()->initialize(); engine = memnew(Engine); @@ -680,6 +682,8 @@ int Main::test_entrypoint(int argc, char *argv[], bool &tests_need_run) { */ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_phase) { + Thread::make_main_thread(); + OS::get_singleton()->initialize(); engine = memnew(Engine); @@ -1876,6 +1880,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph engine->startup_benchmark_end_measure(); // core + Thread::release_main_thread(); // If setup2() is called from another thread, that one will become main thread, so preventively release this one. + if (p_second_phase) { return setup2(); } @@ -1941,7 +1947,9 @@ error: return exit_code; } -Error Main::setup2(Thread::ID p_main_tid_override) { +Error Main::setup2() { + Thread::make_main_thread(); // Make whatever thread call this the main thread. + // Print engine name and version print_line(String(VERSION_NAME) + " v" + get_full_version_string() + " - " + String(VERSION_WEBSITE)); @@ -1962,10 +1970,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) { initialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS); GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SERVERS); - if (p_main_tid_override) { - Thread::main_thread_id = p_main_tid_override; - } - #ifdef TOOLS_ENABLED if (editor || project_manager || cmdline_tool) { EditorPaths::create(); diff --git a/main/main.h b/main/main.h index e345589f59..cc0655cd02 100644 --- a/main/main.h +++ b/main/main.h @@ -60,7 +60,7 @@ public: static int test_entrypoint(int argc, char *argv[], bool &tests_need_run); static Error setup(const char *execpath, int argc, char *argv[], bool p_second_phase = true); - static Error setup2(Thread::ID p_main_tid_override = 0); + static Error setup2(); // The thread calling setup2() will effectively become the main thread. static String get_rendering_driver_name(); #ifdef TESTS_ENABLED static Error test_setup(); |