From f38b7a0641e2380be7e667ff23dca64f4c292516 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 30 Oct 2023 17:51:44 +0100 Subject: [PATCH 1/3] make browser to use portable timer in MT --- .../System.Private.CoreLib/System.Private.CoreLib.csproj | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj index d1f463b24c58bc..402826241612bb 100644 --- a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -123,7 +123,7 @@ true true true - true + true true true true @@ -273,9 +273,6 @@ - - - @@ -288,6 +285,7 @@ + From 31f15df2004b0390b57f13dd99a253fbe6eda588 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 30 Oct 2023 17:58:11 +0100 Subject: [PATCH 2/3] more --- src/mono/mono/mini/mini-wasm.c | 14 +++++--------- src/mono/mono/mini/mini-wasm.h | 2 ++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/mono/mono/mini/mini-wasm.c b/src/mono/mono/mini/mini-wasm.c index 6230c1ede105ff..ee3b8f45c7b2db 100644 --- a/src/mono/mono/mini/mini-wasm.c +++ b/src/mono/mono/mini/mini-wasm.c @@ -598,6 +598,8 @@ mono_wasm_execute_timer (void) #endif +#ifdef HOST_BROWSER +#ifdef DISABLE_THREADS void mono_wasm_main_thread_schedule_timer (void *timerHandler, int shortestDueTimeMs) { @@ -605,23 +607,17 @@ mono_wasm_main_thread_schedule_timer (void *timerHandler, int shortestDueTimeMs) g_assert (timerHandler); timer_handler = timerHandler; -#ifdef HOST_BROWSER -#ifndef DISABLE_THREADS - if (!mono_threads_wasm_is_browser_thread ()) { - mono_threads_wasm_async_run_in_main_thread_vi ((void (*)(gpointer))mono_wasm_schedule_timer, GINT_TO_POINTER(shortestDueTimeMs)); - return; - } -#endif mono_wasm_schedule_timer (shortestDueTimeMs); -#endif } +#endif +#endif void mono_arch_register_icall (void) { #ifdef HOST_BROWSER - mono_add_internal_call_internal ("System.Threading.TimerQueue::MainThreadScheduleTimer", mono_wasm_main_thread_schedule_timer); #ifdef DISABLE_THREADS + mono_add_internal_call_internal ("System.Threading.TimerQueue::MainThreadScheduleTimer", mono_wasm_main_thread_schedule_timer); mono_add_internal_call_internal ("System.Threading.ThreadPool::MainThreadScheduleBackgroundJob", mono_main_thread_schedule_background_job); #else mono_add_internal_call_internal ("System.Runtime.InteropServices.JavaScript.JSSynchronizationContext::TargetThreadScheduleBackgroundJob", mono_target_thread_schedule_background_job); diff --git a/src/mono/mono/mini/mini-wasm.h b/src/mono/mono/mini/mini-wasm.h index 796b7a0069bdbb..48e6906c10c51f 100644 --- a/src/mono/mono/mini/mini-wasm.h +++ b/src/mono/mono/mini/mini-wasm.h @@ -100,7 +100,9 @@ typedef struct { // sdks/wasm/driver.c is C and uses this G_EXTERN_C void mono_wasm_enable_debugging (int log_level); +#ifdef DISABLE_THREADS void mono_wasm_main_thread_schedule_timer (void *timerHandler, int shortestDueTimeMs); +#endif // DISABLE_THREADS void mono_wasm_print_stack_trace (void); From 7e0f1b7754f58c7ba290a87b8829aaf9756a1ece Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 30 Oct 2023 18:22:21 +0100 Subject: [PATCH 3/3] fix wasi --- src/mono/mono/mini/mini-wasm.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/mono/mono/mini/mini-wasm.c b/src/mono/mono/mini/mini-wasm.c index ee3b8f45c7b2db..0ea20e8397292e 100644 --- a/src/mono/mono/mini/mini-wasm.c +++ b/src/mono/mono/mini/mini-wasm.c @@ -557,9 +557,6 @@ mono_init_native_crash_info (void) #endif -// this points to System.Threading.TimerQueue.TimerHandler C# method -static void *timer_handler; - #ifdef HOST_BROWSER void @@ -583,6 +580,9 @@ mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo return FALSE; } +// this points to System.Threading.TimerQueue.TimerHandler C# method +static void *timer_handler; + EMSCRIPTEN_KEEPALIVE void mono_wasm_execute_timer (void) { @@ -595,10 +595,6 @@ mono_wasm_execute_timer (void) cb (); } - -#endif - -#ifdef HOST_BROWSER #ifdef DISABLE_THREADS void mono_wasm_main_thread_schedule_timer (void *timerHandler, int shortestDueTimeMs)