Skip to content

Commit 7676282

Browse files
committed
call mono_wasm_gc_lock in MonoHeapLock
1 parent 2b04b01 commit 7676282

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { BINDINGType, MONOType } from 'dotnet/dotnet-legacy';
1919
export let BINDING: BINDINGType = undefined as any;
2020
export let MONO: MONOType = undefined as any;
2121
export let Module: DotnetModuleConfig & EmscriptenModule = undefined as any;
22+
export let MONO_INTERNAL: any = undefined as any;
2223

2324
const uint64HighOrderShift = Math.pow(2, 32);
2425
const maxSafeNumberHighPart = Math.pow(2, 21) - 1; // The high-order int32 from Number.MAX_SAFE_INTEGER
@@ -146,7 +147,7 @@ export const monoPlatform: Platform = {
146147

147148
beginHeapLock: function beginHeapLock() {
148149
assertHeapIsNotLocked();
149-
currentHeapLock = new MonoHeapLock();
150+
currentHeapLock = MonoHeapLock.create();
150151
return currentHeapLock;
151152
},
152153

@@ -358,10 +359,11 @@ async function createRuntimeInstance(resourceLoader: WebAssemblyResourceLoader):
358359
(dotnet as any).withModuleConfig(moduleConfig);
359360

360361
const runtime = await dotnet.create();
361-
const { MONO: mono, BINDING: binding, Module: module, setModuleImports } = runtime;
362+
const { MONO: mono, BINDING: binding, Module: module, setModuleImports, INTERNAL: mono_internal } = runtime;
362363
Module = module;
363364
BINDING = binding;
364365
MONO = mono;
366+
MONO_INTERNAL = mono_internal;
365367

366368
Blazor._internal.dotNetCriticalError = printErr;
367369
Blazor._internal.loadLazyAssembly = (assemblyNameToLoad) => loadLazyAssembly(resourceLoader, assemblyNameToLoad);
@@ -554,6 +556,10 @@ class MonoHeapLock implements HeapLock {
554556
throw new Error('Trying to release a lock which isn\'t current');
555557
}
556558

559+
if (typeof MONO_INTERNAL !== 'undefined' && typeof MONO_INTERNAL.mono_wasm_gc_unlock === 'function') {
560+
MONO_INTERNAL.mono_wasm_gc_unlock();
561+
}
562+
557563
currentHeapLock = null;
558564

559565
while (this.postReleaseActions?.length) {
@@ -566,4 +572,11 @@ class MonoHeapLock implements HeapLock {
566572
assertHeapIsNotLocked();
567573
}
568574
}
575+
576+
static create(): MonoHeapLock {
577+
if (typeof MONO_INTERNAL !== 'undefined' && typeof MONO_INTERNAL.mono_wasm_gc_lock === 'function') {
578+
MONO_INTERNAL.mono_wasm_gc_lock();
579+
}
580+
return new MonoHeapLock();
581+
}
569582
}

0 commit comments

Comments
 (0)