44import WasmEnableThreads from "consts:wasmEnableThreads" ;
55
66import cwraps from "./cwraps" ;
7- import { ENVIRONMENT_IS_WORKER , Module , loaderHelpers } from "./globals" ;
7+ import { Module , loaderHelpers } from "./globals" ;
88import { forceThreadMemoryViewRefresh } from "./memory" ;
9- import { is_thread_available } from "./pthreads" ;
109
1110let spread_timers_maximum = 0 ;
1211let pump_count = 0 ;
1312
1413export function prevent_timer_throttling ( ) : void {
14+ if ( WasmEnableThreads ) return ;
1515 if ( ! loaderHelpers . isChromium ) {
1616 return ;
1717 }
@@ -30,66 +30,46 @@ export function prevent_timer_throttling (): void {
3030}
3131
3232function prevent_timer_throttling_tick ( ) {
33+ if ( WasmEnableThreads ) return ;
3334 Module . maybeExit ( ) ;
3435 if ( ! loaderHelpers . is_runtime_running ( ) ) {
3536 return ;
3637 }
37- if ( WasmEnableThreads ) {
38- forceThreadMemoryViewRefresh ( ) ;
39- }
4038 cwraps . mono_wasm_execute_timer ( ) ;
4139 pump_count ++ ;
4240 mono_background_exec_until_done ( ) ;
4341}
4442
4543function mono_background_exec_until_done ( ) {
44+ if ( WasmEnableThreads ) return ;
4645 Module . maybeExit ( ) ;
4746 if ( ! loaderHelpers . is_runtime_running ( ) ) {
4847 return ;
4948 }
50- if ( WasmEnableThreads ) {
51- forceThreadMemoryViewRefresh ( ) ;
52- }
5349 while ( pump_count > 0 ) {
5450 -- pump_count ;
5551 cwraps . mono_background_exec ( ) ;
5652 }
5753}
5854
5955export function schedule_background_exec ( ) : void {
56+ if ( WasmEnableThreads ) return ;
6057 ++ pump_count ;
61- let max_postpone_count = 10 ;
62- function postpone_schedule_background ( ) {
63- if ( max_postpone_count < 0 || is_thread_available ( ) ) {
64- Module . safeSetTimeout ( mono_background_exec_until_done , 0 ) ;
65- } else {
66- max_postpone_count -- ;
67- Module . safeSetTimeout ( postpone_schedule_background , 10 ) ;
68- }
69- }
70-
71- if ( WasmEnableThreads && ! ENVIRONMENT_IS_WORKER ) {
72- // give threads chance to load before we run more synchronous code on UI thread
73- postpone_schedule_background ( ) ;
74- } else {
75- Module . safeSetTimeout ( mono_background_exec_until_done , 0 ) ;
76- }
58+ Module . safeSetTimeout ( mono_background_exec_until_done , 0 ) ;
7759}
7860
7961let lastScheduledTimeoutId : any = undefined ;
8062export function mono_wasm_schedule_timer ( shortestDueTimeMs : number ) : void {
63+ if ( WasmEnableThreads ) return ;
8164 if ( lastScheduledTimeoutId ) {
8265 globalThis . clearTimeout ( lastScheduledTimeoutId ) ;
8366 lastScheduledTimeoutId = undefined ;
84- // NOTE: Multi-threaded Module.safeSetTimeout() does the runtimeKeepalivePush()
85- // and non-Multi-threaded Module.safeSetTimeout does not runtimeKeepalivePush()
86- // but clearTimeout does not runtimeKeepalivePop() so we need to do it here in MT only.
87- if ( WasmEnableThreads ) Module . runtimeKeepalivePop ( ) ;
8867 }
8968 lastScheduledTimeoutId = Module . safeSetTimeout ( mono_wasm_schedule_timer_tick , shortestDueTimeMs ) ;
9069}
9170
9271function mono_wasm_schedule_timer_tick ( ) {
72+ if ( WasmEnableThreads ) return ;
9373 Module . maybeExit ( ) ;
9474 if ( WasmEnableThreads ) {
9575 forceThreadMemoryViewRefresh ( ) ;
0 commit comments