Skip to content

Commit

Permalink
Prepare for new p/invoke code, step #1
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Jul 19, 2024
1 parent 7346dbe commit ab79d1b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/native/monodroid/embedded-assemblies.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<uint8_t*>(map_info.area);
} else {
uint8_t *expected_null = nullptr;
Expand Down
6 changes: 0 additions & 6 deletions src/native/monodroid/monodroid-glue-internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/native/monodroid/monodroid-glue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "timing-internal.hh"
#include "search.hh"
#include "runtime-util.hh"
#include "monodroid-state.hh"

//#include "xamarin_getifaddrs.h"

Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/native/monodroid/timing-internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "strings.hh"
#include "util.hh"
#include "shared-constants.hh"
#include "monodroid-state.hh"

namespace xamarin::android::internal
{
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/native/monodroid/timing.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "timing.hh"
#include "timing-internal.hh"

using namespace xamarin::android;
Expand Down
21 changes: 21 additions & 0 deletions src/native/runtime-base/monodroid-state.hh
Original file line number Diff line number Diff line change
@@ -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;
};
}
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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;
}
Expand All @@ -21,7 +22,7 @@ namespace xamarin::android::internal

~StartupAwareLock ()
{
if (MonodroidRuntime::is_startup_in_progress ()) {
if (MonodroidState::is_startup_in_progress ()) {
return;
}

Expand Down

0 comments on commit ab79d1b

Please sign in to comment.