@@ -58,7 +58,6 @@ private sealed record WaitEntry (LowLevelLifoAsyncWaitSemaphore Semaphore, Actio
5858
5959 public void PrepareAsyncWait ( int timeoutMs , Action < LowLevelLifoAsyncWaitSemaphore , object ? > onSuccess , Action < LowLevelLifoAsyncWaitSemaphore , object ? > onTimeout , object ? state )
6060 {
61- //FIXME(ak): the async wait never spins. Shoudl we spin a little?
6261 Debug . Assert ( timeoutMs >= - 1 ) ;
6362
6463 // Try to acquire the semaphore or
@@ -112,16 +111,12 @@ private void PrepareAsyncWaitForSignal(int timeoutMs, Action<LowLevelLifoAsyncWa
112111
113112 _onWait ( ) ;
114113
115- if ( timeoutMs == 0 ) {
116- onTimeout ( this , state ) ;
117- return ;
118- }
119114 WaitEntry we = new WaitEntry ( this , onSuccess , onTimeout , state )
120115 {
121116 TimeoutMs = timeoutMs ,
122117 StartWaitTicks = timeoutMs != - 1 ? Environment . TickCount : 0 ,
123118 } ;
124- PrepareAsyncWaitCore ( timeoutMs , we ) ;
119+ PrepareAsyncWaitCore ( we ) ;
125120 // on success calls InternalAsyncWaitSuccess, on timeout calls InternalAsyncWaitTimeout
126121 }
127122
@@ -180,17 +175,23 @@ private static void InternalAsyncWaitSuccess(LowLevelLifoAsyncWaitSemaphore self
180175 we . TimeoutMs = 0 ;
181176 we . StartWaitTicks = endWaitTicks ;
182177 }
183- self . PrepareAsyncWaitCore ( we . TimeoutMs , we ) ;
178+ PrepareAsyncWaitCore ( we ) ;
184179 // on success calls InternalAsyncWaitSuccess, on timeout calls InternalAsyncWaitTimeout
185180 }
186181
187- private void PrepareAsyncWaitCore ( int timeout_ms , WaitEntry internalWaitEntry )
182+ private static void PrepareAsyncWaitCore ( WaitEntry internalWaitEntry )
188183 {
184+ int timeoutMs = internalWaitEntry . TimeoutMs ;
185+ LowLevelLifoAsyncWaitSemaphore semaphore = internalWaitEntry . Semaphore ;
186+ if ( timeoutMs == 0 ) {
187+ internalWaitEntry . OnTimeout ( semaphore , internalWaitEntry . State ) ;
188+ return ;
189+ }
189190 GCHandle gchandle = GCHandle . Alloc ( internalWaitEntry ) ;
190191 unsafe {
191192 delegate * unmanaged< IntPtr , IntPtr , void > successCallback = & SuccessCallback ;
192193 delegate * unmanaged< IntPtr , IntPtr , void > timeoutCallback = & TimeoutCallback ;
193- PrepareAsyncWaitInternal ( lifo_semaphore , timeout_ms , successCallback , timeoutCallback , GCHandle . ToIntPtr ( gchandle ) ) ;
194+ PrepareAsyncWaitInternal ( semaphore . lifo_semaphore , timeoutMs , successCallback , timeoutCallback , GCHandle . ToIntPtr ( gchandle ) ) ;
194195 }
195196 }
196197
0 commit comments