Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ private TimerQueue(int id)
}

[DynamicDependency("TimeoutCallback")]
// The id argument is unused in netcore
// This replaces the current pending setTimeout with shorter one
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void SetTimeout(int timeout, int id);
private static extern void SetTimeout(int timeout);

// Called by mini-wasm.c:mono_set_timeout_exec
private static void TimeoutCallback()
Expand Down Expand Up @@ -78,7 +77,7 @@ private static void ReplaceNextSetTimeout(long shortestDueTimeMs, long currentTi
int shortestWait = Math.Max((int)(shortestDueTimeMs - currentTimeMs), 0);
// this would cancel the previous schedule and create shorter one
// it is expensive call
SetTimeout(shortestWait, 0);
SetTimeout(shortestWait);
}
}

Expand Down
39 changes: 22 additions & 17 deletions src/mono/mono/mini/mini-wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_targe

//functions exported to be used by JS
G_BEGIN_DECLS
EMSCRIPTEN_KEEPALIVE void mono_set_timeout_exec (int id);
EMSCRIPTEN_KEEPALIVE void mono_set_timeout_exec (void);

//JS functions imported that we use
extern void mono_set_timeout (int t, int d);
extern void mono_set_timeout (int t);
extern void mono_wasm_queue_tp_cb (void);
G_END_DECLS

Expand Down Expand Up @@ -581,21 +581,23 @@ mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo
}

EMSCRIPTEN_KEEPALIVE void
mono_set_timeout_exec (int id)
mono_set_timeout_exec (void)
{
ERROR_DECL (error);

MonoClass *klass = mono_class_load_from_name (mono_defaults.corlib, "System.Threading", "TimerQueue");
g_assert (klass);
static MonoMethod *method = NULL;
if (method == NULL) {
MonoClass *klass = mono_class_load_from_name (mono_defaults.corlib, "System.Threading", "TimerQueue");
g_assert (klass);

MonoMethod *method = mono_class_get_method_from_name_checked (klass, "TimeoutCallback", -1, 0, error);
mono_error_assert_ok (error);
g_assert (method);
method = mono_class_get_method_from_name_checked (klass, "TimeoutCallback", -1, 0, error);
mono_error_assert_ok (error);
g_assert (method);
}

gpointer params[1] = { &id };
MonoObject *exc = NULL;

mono_runtime_try_invoke (method, NULL, params, &exc, error);
mono_runtime_try_invoke (method, NULL, NULL, &exc, error);

//YES we swallow exceptions cuz there's nothing much we can do from here.
//FIXME Maybe call the unhandled exception function?
Expand All @@ -614,10 +616,10 @@ mono_set_timeout_exec (int id)
#endif

void
mono_wasm_set_timeout (int timeout, int id)
mono_wasm_set_timeout (int timeout)
{
#ifdef HOST_BROWSER
mono_set_timeout (timeout, id);
mono_set_timeout (timeout);
#endif
}

Expand All @@ -626,12 +628,15 @@ tp_cb (void)
{
ERROR_DECL (error);

MonoClass *klass = mono_class_load_from_name (mono_defaults.corlib, "System.Threading", "ThreadPool");
g_assert (klass);
static MonoMethod *method = NULL;
if (method == NULL) {
MonoClass *klass = mono_class_load_from_name (mono_defaults.corlib, "System.Threading", "ThreadPool");
g_assert (klass);

MonoMethod *method = mono_class_get_method_from_name_checked (klass, "Callback", -1, 0, error);
mono_error_assert_ok (error);
g_assert (method);
method = mono_class_get_method_from_name_checked (klass, "Callback", -1, 0, error);
mono_error_assert_ok (error);
g_assert (method);
}

MonoObject *exc = NULL;

Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/mini-wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ typedef struct {
// sdks/wasm/driver.c is C and uses this
G_EXTERN_C void mono_wasm_enable_debugging (int log_level);

void mono_wasm_set_timeout (int timeout, int id);
void mono_wasm_set_timeout (int timeout);

int mono_wasm_assembly_already_added (const char *assembly_name);
void mono_wasm_print_stack_trace (void);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/cwraps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const fn_signatures: [ident: string, returnType: string | null, argTypes?: strin
["mono_wasm_parse_runtime_options", null, ["number", "number"]],
["mono_wasm_strdup", "number", ["string"]],
["mono_background_exec", null, []],
["mono_set_timeout_exec", null, ["number"]],
["mono_set_timeout_exec", null, []],
["mono_wasm_load_icu_data", "number", ["number"]],
["mono_wasm_get_icudt_name", "string", ["string"]],
["mono_wasm_add_assembly", "number", ["string", "number", "number"]],
Expand Down Expand Up @@ -82,7 +82,7 @@ export interface t_Cwraps {
mono_wasm_strdup(value: string): number;
mono_wasm_parse_runtime_options(length: number, argv: VoidPtr): void;
mono_background_exec(): void;
mono_set_timeout_exec(id: number): void;
mono_set_timeout_exec(): void;
mono_wasm_load_icu_data(offset: VoidPtr): number;
mono_wasm_get_icudt_name(name: string): string;
mono_wasm_add_assembly(name: string, data: VoidPtr, size: number): number;
Expand Down
6 changes: 3 additions & 3 deletions src/mono/wasm/runtime/scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function prevent_timer_throttling(): void {
for (let schedule = next_reach_time; schedule < desired_reach_time; schedule += light_throttling_frequency) {
const delay = schedule - now;
setTimeout(() => {
cwraps.mono_set_timeout_exec(0);
cwraps.mono_set_timeout_exec();
pump_count++;
pump_message();
}, delay);
Expand All @@ -52,9 +52,9 @@ export function schedule_background_exec(): void {
}

let lastScheduledTimeoutId: any = undefined;
export function mono_set_timeout(timeout: number, id: number): void {
export function mono_set_timeout(timeout: number): void {
function mono_wasm_set_timeout_exec() {
cwraps.mono_set_timeout_exec(id);
cwraps.mono_set_timeout_exec();
}
if (lastScheduledTimeoutId) {
clearTimeout(lastScheduledTimeoutId);
Expand Down