diff --git a/src/native/monodroid/embedded-assemblies.cc b/src/native/monodroid/embedded-assemblies.cc index 07eddf61114..57733c6349e 100644 --- a/src/native/monodroid/embedded-assemblies.cc +++ b/src/native/monodroid/embedded-assemblies.cc @@ -33,6 +33,7 @@ #include "xamarin-app.hh" #include "cpp-util.hh" #include "monodroid-glue-internal.hh" +#include "monodroid-state.hh" #include "startup-aware-lock.hh" #include "timing-internal.hh" #include "search.hh" @@ -179,7 +180,7 @@ EmbeddedAssemblies::map_runtime_file (XamarinAndroidBundledAssembly& file) noexc close (fd); } - if (MonodroidRuntime::is_startup_in_progress ()) { + if (MonodroidState::is_startup_in_progress ()) { file.data = static_cast(map_info.area); } else { uint8_t *expected_null = nullptr; diff --git a/src/native/monodroid/monodroid-glue-internal.hh b/src/native/monodroid/monodroid-glue-internal.hh index a8245495dd4..9f6a39d1b84 100644 --- a/src/native/monodroid/monodroid-glue-internal.hh +++ b/src/native/monodroid/monodroid-glue-internal.hh @@ -170,11 +170,6 @@ namespace xamarin::android::internal jint Java_JNI_OnLoad (JavaVM *vm, void *reserved); - static bool is_startup_in_progress () noexcept - { - return startup_in_progress; - } - int get_android_api_level () const { return android_api_level; @@ -341,7 +336,6 @@ namespace xamarin::android::internal * able to switch our different contexts from different threads. */ int current_context_id = -1; - static bool startup_in_progress; jnienv_register_jni_natives_fn jnienv_register_jni_natives = nullptr; MonoAssemblyLoadContextGCHandle default_alc = nullptr; diff --git a/src/native/monodroid/monodroid-glue.cc b/src/native/monodroid/monodroid-glue.cc index 49cd5871b2b..f4328e9c7d9 100644 --- a/src/native/monodroid/monodroid-glue.cc +++ b/src/native/monodroid/monodroid-glue.cc @@ -65,6 +65,7 @@ #include "timing-internal.hh" #include "search.hh" #include "runtime-util.hh" +#include "monodroid-state.hh" //#include "xamarin_getifaddrs.h" @@ -87,7 +88,6 @@ MonoCoreRuntimeProperties MonodroidRuntime::monovm_core_properties = { }; std::mutex MonodroidRuntime::dso_handle_write_lock; -bool MonodroidRuntime::startup_in_progress = true; void MonodroidRuntime::thread_start ([[maybe_unused]] MonoProfiler *prof, [[maybe_unused]] uintptr_t tid) @@ -1046,7 +1046,7 @@ MonodroidRuntime::monodroid_dlopen_log_and_return (void *handle, char **err, con force_inline void* MonodroidRuntime::monodroid_dlopen_ignore_component_or_load ([[maybe_unused]] hash_t name_hash, const char *name, int flags, char **err) noexcept { - if (startup_in_progress) { + if (MonodroidState::is_startup_in_progress ()) { auto ignore_component = [&](const char *label, MonoComponent component) -> bool { if ((application_config.mono_components_mask & component) != component) { log_info (LOG_ASSEMBLY, "Mono '%s' component requested but not packaged, ignoring", label); @@ -1731,7 +1731,7 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl xamarin_app_init (env, get_function_pointer_at_runtime); } #endif // def RELEASE && def ANDROID && def NET - startup_in_progress = false; + MonodroidState::mark_startup_done (); } JNIEXPORT jint JNICALL diff --git a/src/native/monodroid/timing-internal.hh b/src/native/monodroid/timing-internal.hh index 519b98cb28e..076335e891b 100644 --- a/src/native/monodroid/timing-internal.hh +++ b/src/native/monodroid/timing-internal.hh @@ -12,6 +12,7 @@ #include "strings.hh" #include "util.hh" #include "shared-constants.hh" +#include "monodroid-state.hh" namespace xamarin::android::internal { @@ -150,7 +151,7 @@ namespace xamarin::android::internal TimingEvent &ev = events[index]; mark (ev.start); ev.kind = kind; - ev.before_managed = MonodroidRuntime::is_startup_in_progress (); + ev.before_managed = MonodroidState::is_startup_in_progress (); ev.more_info = nullptr; return index; diff --git a/src/native/monodroid/timing.cc b/src/native/monodroid/timing.cc index 023b16271ec..a0e8e1699f2 100644 --- a/src/native/monodroid/timing.cc +++ b/src/native/monodroid/timing.cc @@ -1,3 +1,4 @@ +#include "timing.hh" #include "timing-internal.hh" using namespace xamarin::android; diff --git a/src/native/runtime-base/monodroid-state.hh b/src/native/runtime-base/monodroid-state.hh new file mode 100644 index 00000000000..642e35cb120 --- /dev/null +++ b/src/native/runtime-base/monodroid-state.hh @@ -0,0 +1,21 @@ +#pragma once + +namespace xamarin::android::internal +{ + class MonodroidState + { + public: + static bool is_startup_in_progress () noexcept + { + return startup_in_progress; + } + + static void mark_startup_done () + { + startup_in_progress = false; + } + + private: + inline static bool startup_in_progress = true; + }; +} diff --git a/src/native/monodroid/startup-aware-lock.hh b/src/native/runtime-base/startup-aware-lock.hh similarity index 79% rename from src/native/monodroid/startup-aware-lock.hh rename to src/native/runtime-base/startup-aware-lock.hh index 9800370bcec..b8cd7820ddf 100644 --- a/src/native/monodroid/startup-aware-lock.hh +++ b/src/native/runtime-base/startup-aware-lock.hh @@ -1,7 +1,8 @@ #ifndef __STARTUP_AWARE_LOCK_HH #define __STARTUP_AWARE_LOCK_HH -#include "globals.hh" +#include "cppcompat.hh" +#include "monodroid-state.hh" namespace xamarin::android::internal { @@ -11,7 +12,7 @@ namespace xamarin::android::internal explicit StartupAwareLock (std::mutex &m) : lock (m) { - if (MonodroidRuntime::is_startup_in_progress ()) { + if (MonodroidState::is_startup_in_progress ()) { // During startup we run without threads, do nothing return; } @@ -21,7 +22,7 @@ namespace xamarin::android::internal ~StartupAwareLock () { - if (MonodroidRuntime::is_startup_in_progress ()) { + if (MonodroidState::is_startup_in_progress ()) { return; }