36 namespace System.Threading.Tasks
38 internal struct TaskCompletionQueue<TCompletion> where TCompletion : class
43 public void Add (TCompletion continuation)
45 if (single == null &&
AotInterlocked.CompareExchange (ref single, continuation, null) == null)
47 if (completed == null)
49 completed.TryAdd (continuation);
52 public bool Remove (TCompletion continuation)
54 TCompletion temp = single;
55 if (temp != null && temp == continuation &&
AotInterlocked.CompareExchange (ref single, null, continuation) == continuation)
57 if (completed != null)
58 return completed.TryRemove (continuation);
62 public bool HasElements {
64 return single != null || (completed != null && completed.Count != 0);
68 public bool TryGetNextCompletion (out TCompletion continuation)
72 if (single != null && (continuation =
AotInterlocked.Exchange (ref single, null)) != null)
75 return completed != null && completed.TryPop (out continuation);
Interlocked reference exchanges do not work with the older Mono AOT compiler so this type fudges arou...