@@ -133,9 +133,8 @@ public static unsafe void ContextSet(ContextTask* contextTask)
133133 }
134134
135135 // unsafe because we are using pointers.
136- public static unsafe int Callback ( EventWaitable e , ContextTask * contextPtr )
136+ public static unsafe int Callback ( EventWaitable e )
137137 {
138- Console . WriteLine ( "Callback" ) ;
139138 ContextTask * contextTaskPtr = ContextGet ( ) ;
140139
141140 var waitables = pendingTasks [ contextTaskPtr ->WaitableSetHandle ] ;
@@ -152,77 +151,21 @@ public static unsafe int Callback(EventWaitable e, ContextTask* contextPtr)
152151 waitables . Remove ( e . Waitable , out _ ) ;
153152 if ( e . IsSubtask )
154153 {
155- if ( e . SubtaskStatus . IsStarting )
154+ switch ( e . SubtaskStatus )
156155 {
157- throw new Exception ( "unexpected subtask status Starting " + e . Code ) ;
158- }
159- if ( e . SubtaskStatus . IsStarted || e . SubtaskStatus . IsReturned )
160- {
161- waitableInfoState . SetResult ( e . WaitableCount ) ;
162- Interop . SubtaskDrop ( e . Waitable ) ;
163- }
164- else
165- {
166- throw new Exception ( "TODO: subtask status " + e . Code ) ;
167- }
168- }
169- else
170- {
171- if ( e . IsDropped )
172- {
173- waitableInfoState . SetException ( new StreamDroppedException ( ) ) ;
174- }
175- else
176- {
177- // This may add a new waitable to the set.
178- waitableInfoState . SetResult ( e . WaitableCount ) ;
179- }
180- }
156+ case { IsStarting : true } :
157+ throw new Exception ( "unexpected subtask status Starting " + e . Code ) ;
181158
182- if ( waitables . Count == 0 )
183- {
184- ContextSet ( null ) ;
185- Marshal . FreeHGlobal ( ( IntPtr ) contextTaskPtr ) ;
186- return ( int ) CallbackCode . Exit ;
187- }
159+ case { IsStarted : true } :
160+ break ;
188161
189- return ( int ) CallbackCode . Wait | ( int ) ( contextTaskPtr ->WaitableSetHandle << 4 ) ;
190- }
162+ case { IsReturned : true } :
163+ waitableInfoState . SetResult ( e . WaitableCount ) ;
164+ Interop . SubtaskDrop ( e . Waitable ) ;
165+ break ;
191166
192- throw new NotImplementedException ( $ "WaitableStatus not implemented { e . WaitableStatus . State } in set { contextTaskPtr ->WaitableSetHandle } ") ;
193- }
194-
195- // unsafe because we are using pointers.
196- public static unsafe int Callback < T > ( EventWaitable e , Func < T > liftFunc )
197- {
198- Console . WriteLine ( "Callback" ) ;
199- ContextTask * contextTaskPtr = ContextGet ( ) ;
200-
201- var waitables = pendingTasks [ contextTaskPtr ->WaitableSetHandle ] ;
202- var waitableInfoState = waitables [ e . Waitable ] ;
203-
204- if ( e . IsDropped )
205- {
206- waitableInfoState . FutureStream ! . OtherSideDropped ( ) ;
207- }
208-
209- if ( e . IsCompleted || e . IsDropped )
210- {
211- // The operation is complete so we can free the buffer and remove the waitable from our dicitonary
212- waitables . Remove ( e . Waitable , out _ ) ;
213- if ( e . IsSubtask )
214- {
215- if ( e . SubtaskStatus . IsStarting )
216- {
217- throw new Exception ( "unexpected subtask status Starting " + e . Code ) ;
218- }
219- if ( e . SubtaskStatus . IsStarted || e . SubtaskStatus . IsReturned )
220- {
221- Interop . SubtaskDrop ( e . Waitable ) ;
222- }
223- else
224- {
225- throw new Exception ( "TODO: subtask status " + e . Code ) ;
167+ default :
168+ throw new Exception ( "TODO: subtask status " + e . Code ) ;
226169 }
227170 }
228171 else
@@ -294,10 +237,6 @@ public static unsafe Task<T> TaskFromStatus<T>(uint status, Func<T> liftFunc)
294237 }
295238
296239 var intTaskCompletionSource = new TaskCompletionSource < int > ( ) ;
297- intTaskCompletionSource . Task . ContinueWith ( t =>
298- {
299- Console . WriteLine ( "intTaskCompletionSource continuewith" ) ;
300- } , TaskContinuationOptions . ExecuteSynchronously ) ;
301240 var tcs = new LiftingTaskCompletionSource < T > ( intTaskCompletionSource , liftFunc ) ;
302241 Join ( subtaskStatus . Handle , contextTaskPtr ->WaitableSetHandle , new WaitableInfoState ( intTaskCompletionSource ) ) ;
303242
0 commit comments