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
4 changes: 3 additions & 1 deletion src/mono/browser/runtime/marshal-to-cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
set_arg_element_type, ManagedObject, JavaScriptMarshalerArgSize, proxy_debug_symbol, get_arg_gc_handle, get_arg_type
} from "./marshal";
import { get_marshaler_to_js_by_type } from "./marshal-to-js";
import { _zero_region, localHeapViewF64, localHeapViewI32, localHeapViewU8 } from "./memory";
import { _zero_region, forceThreadMemoryViewRefresh, localHeapViewF64, localHeapViewI32, localHeapViewU8 } from "./memory";
import { stringToMonoStringRoot, stringToUTF16 } from "./strings";
import { JSMarshalerArgument, JSMarshalerArguments, JSMarshalerType, MarshalerToCs, MarshalerToJs, BoundMarshalerToCs, MarshalerType } from "./types/internal";
import { TypedArray } from "./types/emscripten";
Expand Down Expand Up @@ -359,6 +359,7 @@ function _marshal_task_to_cs(arg: JSMarshalerArgument, value: Promise<any>, _?:
mono_assert(!holder.isCanceled, "This promise already canceled.");
holder.isResolved = true;
if (WasmEnableThreads) {
forceThreadMemoryViewRefresh();
settleUnsettledPromise();
}
// we can unregister the GC handle just on JS side
Expand Down Expand Up @@ -387,6 +388,7 @@ function _marshal_task_to_cs(arg: JSMarshalerArgument, value: Promise<any>, _?:
mono_assert(!holder.isResolved, "This promise already resolved.");
holder.isResolved = true;
if (WasmEnableThreads) {
forceThreadMemoryViewRefresh();
settleUnsettledPromise();
}
// we can unregister the GC handle just on JS side
Expand Down
5 changes: 4 additions & 1 deletion src/mono/browser/runtime/marshal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import WasmEnableThreads from "consts:wasmEnableThreads";

import { js_owned_gc_handle_symbol, teardown_managed_proxy } from "./gc-handles";
import { Module, loaderHelpers, mono_assert, runtimeHelpers } from "./globals";
import { getF32, getF64, getI16, getI32, getI64Big, getU16, getU32, getU8, setF32, setF64, setI16, setI32, setI64Big, setU16, setU32, setU8, localHeapViewF64, localHeapViewI32, localHeapViewU8, _zero_region, getB32, setB32 } from "./memory";
import { getF32, getF64, getI16, getI32, getI64Big, getU16, getU32, getU8, setF32, setF64, setI16, setI32, setI64Big, setU16, setU32, setU8, localHeapViewF64, localHeapViewI32, localHeapViewU8, _zero_region, getB32, setB32, forceThreadMemoryViewRefresh } from "./memory";
import { mono_wasm_new_external_root } from "./roots";
import { GCHandle, JSHandle, MonoObject, MonoString, GCHandleNull, JSMarshalerArguments, JSFunctionSignature, JSMarshalerType, JSMarshalerArgument, MarshalerToJs, MarshalerToCs, WasmRoot, MarshalerType } from "./types/internal";
import { TypedArray, VoidPtr } from "./types/emscripten";
Expand All @@ -24,6 +24,9 @@ export const JSMarshalerTypeSize = 32;
export const JSMarshalerSignatureHeaderSize = 4 * 8; // without Exception and Result

export function alloc_stack_frame(size: number): JSMarshalerArguments {
if (WasmEnableThreads) {
forceThreadMemoryViewRefresh();
}
const bytes = JavaScriptMarshalerArgSize * size;
const args = Module.stackAlloc(bytes) as any;
_zero_region(args, bytes);
Expand Down
3 changes: 3 additions & 0 deletions src/mono/browser/runtime/scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ function prevent_timer_throttling_tick() {
if (!loaderHelpers.is_runtime_running()) {
return;
}
if (WasmEnableThreads) {
forceThreadMemoryViewRefresh();
}
cwraps.mono_wasm_execute_timer();
pump_count++;
mono_background_exec_until_done();
Expand Down
14 changes: 13 additions & 1 deletion src/mono/browser/runtime/web-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import WasmEnableThreads from "consts:wasmEnableThreads";
import { prevent_timer_throttling } from "./scheduling";
import { Queue } from "./queue";
import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, createPromiseController, loaderHelpers, mono_assert } from "./globals";
import { setI32, localHeapViewU8 } from "./memory";
import { setI32, localHeapViewU8, forceThreadMemoryViewRefresh } from "./memory";
import { VoidPtr } from "./types/emscripten";
import { PromiseController } from "./types/internal";
import { mono_log_warn } from "./logging";
Expand Down Expand Up @@ -69,6 +69,9 @@ export function ws_wasm_create(uri: string, sub_protocols: string[] | null, rece
try {
if (ws[wasm_ws_is_aborted]) return;
if (!loaderHelpers.is_runtime_running()) return;
if (WasmEnableThreads) {
forceThreadMemoryViewRefresh();
}
open_promise_control.resolve(ws);
prevent_timer_throttling();
} catch (error: any) {
Expand All @@ -79,6 +82,9 @@ export function ws_wasm_create(uri: string, sub_protocols: string[] | null, rece
try {
if (ws[wasm_ws_is_aborted]) return;
if (!loaderHelpers.is_runtime_running()) return;
if (WasmEnableThreads) {
forceThreadMemoryViewRefresh();
}
web_socket_on_message(ws, ev);
prevent_timer_throttling();
} catch (error: any) {
Expand All @@ -90,6 +96,9 @@ export function ws_wasm_create(uri: string, sub_protocols: string[] | null, rece
ws.removeEventListener("message", local_on_message);
if (ws[wasm_ws_is_aborted]) return;
if (!loaderHelpers.is_runtime_running()) return;
if (WasmEnableThreads) {
forceThreadMemoryViewRefresh();
}

ws[wasm_ws_close_received] = true;
ws["close_status"] = ev.code;
Expand Down Expand Up @@ -119,6 +128,9 @@ export function ws_wasm_create(uri: string, sub_protocols: string[] | null, rece
try {
if (ws[wasm_ws_is_aborted]) return;
if (!loaderHelpers.is_runtime_running()) return;
if (WasmEnableThreads) {
forceThreadMemoryViewRefresh();
}
ws.removeEventListener("message", local_on_message);
const message = ev.message
? "WebSocket error: " + ev.message
Expand Down