33
44using System . Collections . Generic ;
55using System . Diagnostics ;
6- using System . Diagnostics . CodeAnalysis ;
76using System . Runtime . CompilerServices ;
87using System . Runtime . InteropServices ;
98
@@ -23,24 +22,18 @@ internal partial class TimerQueue
2322 private static List < TimerQueue > ? s_scheduledTimersToFire ;
2423 private static long s_shortestDueTimeMs = long . MaxValue ;
2524
26- // this means that it's in the s_scheduledTimers collection , not that it's the one which would run on the next TimeoutCallback
25+ // Tracks membership in s_scheduledTimers, not whether this queue is due on the next callback.
2726 private bool _isScheduled ;
2827 private long _scheduledDueTimeMs ;
2928 private TimerQueue ( int _ )
3029 {
3130 }
3231
33- // This replaces the current pending setTimeout with shorter one
34- #if MONO
35- [ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
36- private static extern unsafe void MainThreadScheduleTimer ( void * callback , int shortestDueTimeMs ) ;
37- #else
3832 [ LibraryImport ( RuntimeHelpers . QCall ) ]
39- private static unsafe partial void SystemJS_ScheduleTimer ( int shortestDueTimeMs ) ;
40- #endif
33+ private static partial void SystemJS_ScheduleTimer ( int shortestDueTimeMs ) ;
4134
35+ // JavaScript invokes this export to process due timers.
4236 [ UnmanagedCallersOnly ( EntryPoint = "SystemJS_ExecuteTimerCallback" ) ]
43- // this callback will arrive on the main thread, called from mono_wasm_execute_timer
4437 private static void TimerHandler ( )
4538 {
4639 try
@@ -78,8 +71,7 @@ private bool SetTimer(uint actualDuration)
7871 }
7972
8073 // shortest time of all TimerQueues
81- [ DynamicDependency ( "TimerHandler" ) ] // https://github.com/dotnet/runtime/issues/101434
82- private static unsafe void ReplaceNextTimer ( long shortestDueTimeMs , long currentTimeMs )
74+ private static void ReplaceNextTimer ( long shortestDueTimeMs , long currentTimeMs )
8375 {
8476 if ( shortestDueTimeMs == long . MaxValue )
8577 {
@@ -91,12 +83,8 @@ private static unsafe void ReplaceNextTimer(long shortestDueTimeMs, long current
9183 {
9284 s_shortestDueTimeMs = shortestDueTimeMs ;
9385 int shortestWait = Math . Max ( ( int ) ( shortestDueTimeMs - currentTimeMs ) , 0 ) ;
94- // this would cancel the previous schedule and create shorter one, it is expensive callback
95- #if MONO
96- MainThreadScheduleTimer ( ( void * ) ( delegate * unmanaged< void > ) & TimerHandler , shortestWait ) ;
97- #else
86+ // Replace the pending JavaScript timeout only when a timer is due sooner.
9887 SystemJS_ScheduleTimer ( shortestWait ) ;
99- #endif
10088 }
10189 }
10290
0 commit comments