From 6821dfb26eac142990e2b1ac9883b78f28ffccdb Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 19 Aug 2022 02:37:43 +0200 Subject: [PATCH] Ported: Disable threads used to check on plugins to load The functionality is unavailable on Android (requires export capability) and unnecessarily consumes resources - m4gr3d https://github.com/godotengine/godot/commit/3ac6b6a596dad2f57390a8d7926604e349d2d281 --- platform/android/export/export_plugin.cpp | 10 ++++++---- platform/android/export/export_plugin.h | 5 ++++- platform/iphone/export/export.cpp | 22 ++++++++++++++++++---- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index 798a7d75a..dd2ed482a 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -229,6 +229,7 @@ static const int DEFAULT_MIN_SDK_VERSION = 19; // Should match the value in 'pla static const int DEFAULT_TARGET_SDK_VERSION = 32; // Should match the value in 'platform/android/java/app/config.gradle#targetSdk' const String SDK_VERSION_RANGE = vformat("%s,%s,1", DEFAULT_MIN_SDK_VERSION, DEFAULT_TARGET_SDK_VERSION); +#ifndef ANDROID_ENABLED void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) { EditorExportPlatformAndroid *ea = (EditorExportPlatformAndroid *)ud; @@ -260,7 +261,6 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) { } } -#ifndef ANDROID_ENABLED // Check for devices updates String adb = get_adb_path(); if (FileAccess::exists(adb)) { @@ -374,7 +374,6 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) { ea->device_lock.unlock(); } -#endif uint64_t sleep = 300'000; uint64_t wait = 3'000'000; @@ -387,7 +386,6 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) { } } -#ifndef ANDROID_ENABLED if (EditorSettings::get_singleton()->get("export/android/shutdown_adb_on_exit")) { String adb = get_adb_path(); if (!FileAccess::exists(adb)) { @@ -398,8 +396,8 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) { args.push_back("kill-server"); OS::get_singleton()->execute(adb, args, true); } -#endif } +#endif String EditorExportPlatformAndroid::get_project_name(const String &p_name) const { String aname; @@ -3302,10 +3300,14 @@ EditorExportPlatformAndroid::EditorExportPlatformAndroid() { devices_changed.set(); plugins_changed.set(); +#ifndef ANDROID_ENABLED check_for_changes_thread.start(_check_for_changes_poll_thread, this); +#endif } EditorExportPlatformAndroid::~EditorExportPlatformAndroid() { +#ifndef ANDROID_ENABLED quit_request.set(); check_for_changes_thread.wait_to_finish(); +#endif } diff --git a/platform/android/export/export_plugin.h b/platform/android/export/export_plugin.h index b1223de71..96e918184 100644 --- a/platform/android/export/export_plugin.h +++ b/platform/android/export/export_plugin.h @@ -28,6 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "core/config/project_settings.h" #include "core/io/image_loader.h" #include "core/io/json.h" #include "core/io/marshalls.h" @@ -35,7 +36,6 @@ #include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/os/os.h" -#include "core/config/project_settings.h" #include "core/os/safe_refcount.h" #include "core/version.h" #include "drivers/png/png_driver_common.h" @@ -95,10 +95,13 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { Vector devices; SafeFlag devices_changed; Mutex device_lock; + +#ifndef ANDROID_ENABLED Thread check_for_changes_thread; SafeFlag quit_request; static void _check_for_changes_poll_thread(void *ud); +#endif String get_project_name(const String &p_name) const; diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp index a4f2eecf3..75f57b299 100644 --- a/platform/iphone/export/export.cpp +++ b/platform/iphone/export/export.cpp @@ -29,13 +29,13 @@ /*************************************************************************/ #include "export.h" +#include "core/config/project_settings.h" #include "core/io/image_loader.h" #include "core/io/marshalls.h" #include "core/io/resource_saver.h" #include "core/io/zip_io.h" #include "core/os/file_access.h" #include "core/os/os.h" -#include "core/config/project_settings.h" #include "core/os/safe_refcount.h" #include "core/version.h" #include "editor/editor_export.h" @@ -57,8 +57,10 @@ class EditorExportPlatformIOS : public EditorExportPlatform { // Plugins SafeFlag plugins_changed; +#ifndef ANDROID_ENABLED Thread check_for_changes_thread; SafeFlag quit_request; +#endif Mutex plugins_lock; Vector plugins; @@ -141,6 +143,7 @@ class EditorExportPlatformIOS : public EditorExportPlatform { return true; } +#ifndef ANDROID_ENABLED static void _check_for_changes_poll_thread(void *ud) { EditorExportPlatformIOS *ea = (EditorExportPlatformIOS *)ud; @@ -176,15 +179,22 @@ class EditorExportPlatformIOS : public EditorExportPlatform { } } } +#endif protected: virtual void get_preset_features(const Ref &p_preset, List *r_features); virtual void get_export_options(List *r_options); public: - virtual String get_name() const { return "iOS"; } - virtual String get_os_name() const { return "iOS"; } - virtual Ref get_logo() const { return logo; } + virtual String get_name() const { + return "iOS"; + } + virtual String get_os_name() const { + return "iOS"; + } + virtual Ref get_logo() const { + return logo; + } virtual bool should_update_export_options() { bool export_options_changed = plugins_changed.is_set(); @@ -2126,12 +2136,16 @@ EditorExportPlatformIOS::EditorExportPlatformIOS() { plugins_changed.set(); +#ifndef ANDROID_ENABLED check_for_changes_thread.start(_check_for_changes_poll_thread, this); +#endif } EditorExportPlatformIOS::~EditorExportPlatformIOS() { +#ifndef ANDROID_ENABLED quit_request.set(); check_for_changes_thread.wait_to_finish(); +#endif } void register_iphone_exporter() {