From: Jérémie Laval Date: Sat, 15 Oct 2011 12:53:12 +0000 (+0200) Subject: Move CompletionContainer to use ConcurrentOrderedList to allows easier removal X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=73e22738756cf8bfe8cbc49c6188fe23ae1a3fba;p=mono.git Move CompletionContainer to use ConcurrentOrderedList to allows easier removal --- diff --git a/mcs/class/corlib/System.Threading.Tasks/CompletionContainer.cs b/mcs/class/corlib/System.Threading.Tasks/CompletionContainer.cs index 198348f5df4..9409aeee688 100644 --- a/mcs/class/corlib/System.Threading.Tasks/CompletionContainer.cs +++ b/mcs/class/corlib/System.Threading.Tasks/CompletionContainer.cs @@ -38,15 +38,25 @@ namespace System.Threading.Tasks internal struct TaskCompletionQueue where TCompletion : class { TCompletion single; - ConcurrentQueue completed; + ConcurrentOrderedList completed; public void Add (TCompletion continuation) { if (single == null && Interlocked.CompareExchange (ref single, continuation, null) == null) return; if (completed == null) - Interlocked.CompareExchange (ref completed, new ConcurrentQueue (), null); - completed.Enqueue (continuation); + Interlocked.CompareExchange (ref completed, new ConcurrentOrderedList (), null); + completed.TryAdd (continuation); + } + + public bool Remove (TCompletion continuation) + { + TCompletion temp = single; + if (temp != null && temp == continuation && Interlocked.CompareExchange (ref single, null, continuation) == continuation) + return true; + else if (completed != null) + return completed.TryRemove (continuation); + return false; } public bool HasElements { @@ -62,7 +72,7 @@ namespace System.Threading.Tasks if (single != null && (continuation = Interlocked.Exchange (ref single, null)) != null) return true; - return completed != null && completed.TryDequeue (out continuation); + return completed != null && completed.TryPop (out continuation); } } }