@@ -72,9 +72,7 @@ private static class Interop
7272
7373 public static int WaitableSetNew ( )
7474 {
75- var waitableSet = Interop . WaitableSetNew ( ) ;
76- Console . WriteLine ( $ "WaitableSet created with number { waitableSet } ") ;
77- return waitableSet ;
75+ return Interop . WaitableSetNew ( ) ;
7876 }
7977
8078 // unsafe because we are using pointers.
@@ -108,7 +106,6 @@ public static void Join(int handle)
108106
109107 private static void AddTaskToWaitables ( int waitableSetHandle , int waitableHandle , WaitableInfoState waitableInfoState )
110108 {
111- Console . WriteLine ( $ "Adding waitable { waitableHandle } to set { waitableSetHandle } ") ;
112109 var waitableSetOfTasks = pendingTasks . GetOrAdd ( waitableSetHandle , _ => new ConcurrentDictionary < int , WaitableInfoState > ( ) ) ;
113110 waitableSetOfTasks [ waitableHandle ] = waitableInfoState ;
114111 }
@@ -141,27 +138,22 @@ public static unsafe void ContextSet(ContextTask* contextTask)
141138 // unsafe because we are using pointers.
142139 public static unsafe uint Callback ( EventWaitable e , ContextTask * contextPtr , Action ? taskReturn )
143140 {
144- Console . WriteLine ( $ "Callback Event code { e . EventCode } Code { e . Code } Waitable { e . Waitable } Waitable Status { e . WaitableStatus . State } , Count { e . WaitableCount } ") ;
145141 ContextTask * contextTaskPtr = ContextGet ( ) ;
146142
147143 var waitables = pendingTasks [ contextTaskPtr ->WaitableSetHandle ] ;
148144 var waitableInfoState = waitables [ e . Waitable ] ;
149145
150146 if ( e . IsDropped )
151147 {
152- Console . WriteLine ( "Dropped." ) ;
153148 waitableInfoState . FutureStream . OtherSideDropped ( ) ;
154149 }
155150
156151 if ( e . IsCompleted || e . IsDropped )
157152 {
158153 // The operation is complete so we can free the buffer and remove the waitable from our dicitonary
159- Console . WriteLine ( "Setting the result" ) ;
160154 waitables . Remove ( e . Waitable , out _ ) ;
161155 if ( e . IsSubtask )
162156 {
163- Console . WriteLine ( "Callback e.IsSubtask TODO" ) ;
164-
165157 // TODO: Handle/lift async function return values.
166158 waitableInfoState . SetResult ( 0 /* not used */ ) ;
167159 }
@@ -176,15 +168,12 @@ public static unsafe uint Callback(EventWaitable e, ContextTask* contextPtr, Act
176168 else
177169 {
178170 // This may add a new waitable to the set.
179- Console . WriteLine ( "Setting result for non-subtask waitableInfoState" ) ;
180171 waitableInfoState . SetResult ( e . WaitableCount ) ;
181172 }
182173 }
183174
184175 if ( waitables . Count == 0 )
185176 {
186- Console . WriteLine ( $ "No more waitables for waitable { e . Waitable } in set { contextTaskPtr ->WaitableSetHandle } ") ;
187- Console . WriteLine ( $ "taskReturn is null { taskReturn == null } ") ;
188177 if ( taskReturn != null )
189178 {
190179 taskReturn ( ) ;
@@ -194,7 +183,6 @@ public static unsafe uint Callback(EventWaitable e, ContextTask* contextPtr, Act
194183 return ( uint ) CallbackCode . Exit ;
195184 }
196185
197- Console . WriteLine ( "More waitables in the set." ) ;
198186 return ( uint ) CallbackCode . Wait | ( uint ) ( contextTaskPtr ->WaitableSetHandle << 4 ) ;
199187 }
200188
@@ -274,8 +262,6 @@ internal LiftingTaskCompletionSource(TaskCompletionSource<int> innerTaskCompleti
274262 // unsafe because we are working with native memory.
275263 internal static unsafe ContextTask * AllocateAndSetNewContext ( )
276264 {
277- Console . WriteLine ( "AllocateAndSetNewContext creating WaitableSet" ) ;
278-
279265 var contextTaskPtr = ( ContextTask * ) Marshal . AllocHGlobal ( Marshal . SizeOf < ContextTask > ( ) ) ;
280266 contextTaskPtr ->WaitableSetHandle = WaitableSetNew ( ) ;
281267 ContextSet ( contextTaskPtr ) ;
@@ -420,8 +406,6 @@ internal static (StreamReader<T>, StreamWriter<T>) RawStreamNew<T>(StreamVTable
420406 var readerHandle = ( int ) ( packed & 0xFFFFFFFF ) ;
421407 var writerHandle = ( int ) ( packed >> 32 ) ;
422408
423- Console . WriteLine ( $ "Creating reader<T> with handle { readerHandle } ") ;
424- Console . WriteLine ( $ "Creating writer<T> with handle { writerHandle } ") ;
425409 return ( new StreamReader < T > ( readerHandle , vtable ) , new StreamWriter < T > ( writerHandle , vtable ) ) ;
426410 }
427411}
@@ -482,18 +466,14 @@ internal unsafe ComponentTask<int> ReadInternal(Func<GCHandle?> liftBuffer, int
482466 var status = new WaitableStatus ( VTableRead ( bufferHandle == null ? IntPtr . Zero : bufferHandle . Value . AddrOfPinnedObject ( ) , length ) ) ;
483467 if ( status . IsBlocked )
484468 {
485- Console . WriteLine ( "Read Blocked" ) ;
486469 var task = new ComponentTask < int > ( new CancelableRead ( cancelableRead , Handle ) ) ;
487470 ContextTask * contextTaskPtr = AsyncSupport . ContextGet ( ) ;
488471 if ( contextTaskPtr == null )
489472 {
490- Console . WriteLine ( "FutureReader Read Blocked creating WaitableSet" ) ;
491473 contextTaskPtr = AsyncSupport . AllocateAndSetNewContext ( ) ;
492474 }
493- Console . WriteLine ( "blocked read before join" ) ;
494475
495476 AsyncSupport . Join ( Handle , contextTaskPtr ->WaitableSetHandle , new WaitableInfoState ( task , this ) ) ;
496- Console . WriteLine ( "blocked read after join returning task" ) ;
497477 return task ;
498478 }
499479 if ( status . IsCompleted )
@@ -553,7 +533,6 @@ public ComponentTask Read()
553533
554534 internal override uint VTableRead ( IntPtr ptr , int length )
555535 {
556- Console . WriteLine ( "FutureReader VTableRead" ) ;
557536 return VTable . Read ( Handle , ptr ) ;
558537 }
559538
@@ -579,7 +558,6 @@ public ComponentTask<T> Read()
579558 {
580559 if ( it . IsCompletedSuccessfully )
581560 {
582- Console . WriteLine ( "FutureReader<T> Read completed, setting result" ) ;
583561 readTask . SetResult ( buf [ 0 ] ) ;
584562 }
585563 else if ( it . IsCanceled )
@@ -607,7 +585,6 @@ internal DelegatingCancelable(ComponentTask innerTask)
607585 uint ICancelable . Cancel ( )
608586 {
609587 var cancelVal = innerTask . Cancel ( ) ;
610- Console . WriteLine ( $ "Delegating cancel { cancelVal } ") ;
611588 return ( uint ) cancelVal ;
612589 }
613590 }
@@ -708,28 +685,23 @@ internal unsafe ComponentTask<int> WriteInternal(Func<GCHandle?> lowerPayload, i
708685 }
709686 bufferHandle = lowerPayload ( ) ;
710687
711- Console . WriteLine ( "WriterBase WriteInternal eith length " + length ) ;
712688 var status = new WaitableStatus ( VTableWrite ( bufferHandle == null ? IntPtr . Zero : bufferHandle . Value . AddrOfPinnedObject ( ) , length ) ) ;
713689 canDrop = true ; // We can only call drop once something has been written.
714690 if ( status . IsBlocked )
715691 {
716- Console . WriteLine ( "blocked write" ) ;
717692 var tcs = new ComponentTask < int > ( new CancelableWrite ( cancelable , Handle ) ) ;
718693 ContextTask * contextTaskPtr = AsyncSupport . ContextGet ( ) ;
719694 if ( contextTaskPtr == null )
720695 {
721696 contextTaskPtr = AsyncSupport . AllocateAndSetNewContext ( ) ;
722697 }
723- Console . WriteLine ( "blocked write before join" ) ;
724698 AsyncSupport . Join ( Handle , contextTaskPtr ->WaitableSetHandle , new WaitableInfoState ( tcs , this ) ) ;
725- Console . WriteLine ( "blocked write after join" ) ;
726699 return tcs ;
727700 }
728701
729702 if ( status . IsCompleted )
730703 {
731704 bufferHandle ? . Free ( ) ;
732- Console . WriteLine ( $ "Write completed. count is { status . Count } ") ; bufferHandle ? . Free ( ) ;
733705 return ComponentTask < int > . FromResult ( ( int ) status . Count ) ;
734706 }
735707
@@ -899,21 +871,16 @@ internal WaitableInfoState(TaskCompletionSource<int> taskCompletionSource)
899871
900872 internal void SetResult ( int count )
901873 {
902- Console . WriteLine ( "WaitableInfoState SetResult" ) ;
903-
904874 if ( taskCompletionSource != null )
905875 {
906- Console . WriteLine ( "Setting result for Task" ) ;
907876 taskCompletionSource . SetResult ( count ) ;
908877 }
909878 else if ( componentTask != null )
910879 {
911- Console . WriteLine ( "Setting result for void waitable completion source" ) ;
912880 componentTask . SetResult ( ) ;
913881 }
914882 else if ( componentTaskInt != null )
915883 {
916- Console . WriteLine ( "Setting result for componentTaskInt" ) ;
917884 componentTaskInt . SetResult ( count ) ;
918885 }
919886 else
@@ -926,7 +893,6 @@ internal void SetException(Exception e)
926893 {
927894 if ( componentTask != null )
928895 {
929- Console . WriteLine ( "Setting exception waitable completion source" ) ;
930896 componentTask . SetException ( e ) ;
931897 }
932898 else
@@ -956,66 +922,31 @@ public StreamDroppedException(string message) : base(message)
956922public abstract class ComponentTask
957923{
958924 protected readonly ICancelable cancelableVTable ;
959- private Action < ComponentTask > ? continuationAction ;
960925 private bool canCancel = true ;
961926
962927 internal ComponentTask ( ICancelable ? cancelableVTable = null )
963928 {
964929 this . cancelableVTable = cancelableVTable ;
965-
966- // tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
967- // tcs = new TaskCompletionSource();
968- // tcs.Task.ContinueWith(t => {
969- // Console.WriteLine("ComponentTask innert task ContinueWith");
970- // if (continuationAction != null)
971- // {
972- // continuationAction(this);
973- // }
974- // }, TaskContinuationOptions.ExecuteSynchronously);
975- // cts = new CancellationTokenSource();
976-
977- // cts.Token.Register(() => tcs.TrySetCanceled(cts.Token));
978930 }
979931
980932 public abstract Task Task { get ; }
981933
982- // //TODO: We should return a new ComponentTask, or a Task as does Task.ContinueWith.
983- // public void ContinueWith(Action<ComponentTask> continuationAction)
984- // {
985- // Console.WriteLine("ComponentTask adding continuationAction XXXX should not be here?");
986- // tcs.Task.ContinueWith(t =>
987- // {
988- // continuationAction(this);
989- // }, TaskContinuationOptions.ExecuteSynchronously);
990- // this.continuationAction = continuationAction;
991- // }
992-
993934 public abstract bool IsCompleted { get ; }
994935
995- // public void Complete()
996- // {
997- // tcs.TrySetResult(true);
998- // }
999-
1000936 public CancelCode Cancel ( )
1001937 {
1002- Console . WriteLine ( "Cancel entered" ) ;
1003938 if ( ! canCancel )
1004939 {
1005940 return CancelCode . Completed ;
1006941 }
1007942
1008- Console . WriteLine ( "Cancel called on ComponentTask" ) ;
1009943 if ( cancelableVTable == null )
1010944 {
1011945 throw new InvalidOperationException ( "Cannot cancel a task that was created as completed with a result." ) ;
1012946 }
1013947
1014948 uint cancelReturn = cancelableVTable . Cancel ( ) ;
1015- Console . WriteLine ( "vtable Cancel called on ComponentTask" ) ;
1016949 SetCanceled ( ) ;
1017- Console . WriteLine ( "SetCanceled called on ComponentTask" ) ;
1018- Console . WriteLine ( $ "cancelableVTable.Cancel returned { cancelReturn } ") ;
1019950 return ( CancelCode ) cancelReturn ;
1020951 }
1021952
@@ -1048,12 +979,9 @@ public class ComponentTask<T> : ComponentTask
1048979{
1049980 private readonly TaskCompletionSource < T > tcs ;
1050981
1051- // To create a task that is created as completed.
1052982 internal ComponentTask ( ICancelable ? cancelableVTable = null ) : base ( cancelableVTable )
1053983 {
1054- Console . WriteLine ( "ComponentTask<T> created " ) ;
1055984 tcs = new TaskCompletionSource < T > ( ) ;
1056- //tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
1057985 }
1058986
1059987 public override Task Task => tcs . Task ;
@@ -1062,21 +990,13 @@ internal ComponentTask(ICancelable? cancelableVTable = null) : base(cancelableVT
1062990
1063991 public Task ContinueWith ( Action < Task < T > > continuationAction )
1064992 {
1065- Console . WriteLine ( "ComponentTask<T> adding continuationAction" ) ;
1066993 return tcs . Task . ContinueWith ( continuationAction , TaskContinuationOptions . ExecuteSynchronously ) ;
1067994 }
1068995
1069996 public void SetResult ( T result )
1070997 {
1071998 SetResult ( ) ;
1072- Console . WriteLine ( "Setting result for ComponentTask<T> on tcs" ) ;
1073- Console . WriteLine ( $ "task status { tcs . Task . Status } ") ;
1074- tcs . Task . ContinueWith ( t => {
1075- Console . WriteLine ( "ComponentTask<T> SetResult task ContinueWith in SetResult" ) ;
1076- } , TaskContinuationOptions . ExecuteSynchronously ) ;
1077-
1078999 tcs . SetResult ( result ) ;
1079- Console . WriteLine ( $ "task status2 { tcs . Task . Status } ") ;
10801000 }
10811001
10821002 public static ComponentTask < T > FromResult < T > ( T result )
@@ -1088,7 +1008,6 @@ public static ComponentTask<T> FromResult<T>(T result)
10881008
10891009 public override void SetCanceled ( )
10901010 {
1091- Console . WriteLine ( "SetCanceled calling tcs.SetCanceled() for ComponentTask<T>" ) ;
10921011 tcs . SetCanceled ( ) ;
10931012 }
10941013
@@ -1102,7 +1021,6 @@ public override void SetException(Exception e)
11021021 /// </summary>
11031022 public new TaskAwaiter < T > GetAwaiter ( )
11041023 {
1105- Console . WriteLine ( "Componenttask<T> GetAwaiter" ) ;
11061024 return tcs . Task . GetAwaiter ( ) ;
11071025 }
11081026
0 commit comments