@@ -19,6 +19,7 @@ import { BINDINGType, MONOType } from 'dotnet/dotnet-legacy';
19
19
export let BINDING : BINDINGType = undefined as any ;
20
20
export let MONO : MONOType = undefined as any ;
21
21
export let Module : DotnetModuleConfig & EmscriptenModule = undefined as any ;
22
+ export let MONO_INTERNAL : any = undefined as any ;
22
23
23
24
const uint64HighOrderShift = Math . pow ( 2 , 32 ) ;
24
25
const maxSafeNumberHighPart = Math . pow ( 2 , 21 ) - 1 ; // The high-order int32 from Number.MAX_SAFE_INTEGER
@@ -146,7 +147,7 @@ export const monoPlatform: Platform = {
146
147
147
148
beginHeapLock : function beginHeapLock ( ) {
148
149
assertHeapIsNotLocked ( ) ;
149
- currentHeapLock = new MonoHeapLock ( ) ;
150
+ currentHeapLock = MonoHeapLock . create ( ) ;
150
151
return currentHeapLock ;
151
152
} ,
152
153
@@ -358,10 +359,11 @@ async function createRuntimeInstance(resourceLoader: WebAssemblyResourceLoader):
358
359
( dotnet as any ) . withModuleConfig ( moduleConfig ) ;
359
360
360
361
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 ;
362
363
Module = module ;
363
364
BINDING = binding ;
364
365
MONO = mono ;
366
+ MONO_INTERNAL = mono_internal ;
365
367
366
368
Blazor . _internal . dotNetCriticalError = printErr ;
367
369
Blazor . _internal . loadLazyAssembly = ( assemblyNameToLoad ) => loadLazyAssembly ( resourceLoader , assemblyNameToLoad ) ;
@@ -554,6 +556,10 @@ class MonoHeapLock implements HeapLock {
554
556
throw new Error ( 'Trying to release a lock which isn\'t current' ) ;
555
557
}
556
558
559
+ if ( typeof MONO_INTERNAL !== 'undefined' && typeof MONO_INTERNAL . mono_wasm_gc_unlock === 'function' ) {
560
+ MONO_INTERNAL . mono_wasm_gc_unlock ( ) ;
561
+ }
562
+
557
563
currentHeapLock = null ;
558
564
559
565
while ( this . postReleaseActions ?. length ) {
@@ -566,4 +572,11 @@ class MonoHeapLock implements HeapLock {
566
572
assertHeapIsNotLocked ( ) ;
567
573
}
568
574
}
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
+ }
569
582
}
0 commit comments