From 4b11dc566a5bbfa1378d6266525c281b028abcc8 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 10 Feb 2017 20:35:12 +0900 Subject: Imported Upstream version 1.0.0.9910 --- .../Threading/Tasks/ProducerConsumerQueues.cs | 171 --------------------- 1 file changed, 171 deletions(-) (limited to 'src/mscorlib/src/System/Threading/Tasks/ProducerConsumerQueues.cs') diff --git a/src/mscorlib/src/System/Threading/Tasks/ProducerConsumerQueues.cs b/src/mscorlib/src/System/Threading/Tasks/ProducerConsumerQueues.cs index 6b9dfbbe37..545bf9a5e5 100644 --- a/src/mscorlib/src/System/Threading/Tasks/ProducerConsumerQueues.cs +++ b/src/mscorlib/src/System/Threading/Tasks/ProducerConsumerQueues.cs @@ -52,11 +52,6 @@ namespace System.Threading.Tasks /// Gets the number of items in the collection. /// In many implementations, this method will not be thread-safe. int Count { get; } - - /// A thread-safe way to get the number of items in the collection. May synchronize access by locking the provided synchronization object. - /// The sync object used to lock - /// The collection count - int GetCountSafe(object syncObj); } /// @@ -80,10 +75,6 @@ namespace System.Threading.Tasks /// Gets the number of items in the collection. int IProducerConsumerQueue.Count { get { return base.Count; } } - - /// A thread-safe way to get the number of items in the collection. May synchronize access by locking the provided synchronization object. - /// ConcurrentQueue.Count is thread safe, no need to acquire the lock. - int IProducerConsumerQueue.GetCountSafe(object syncObj) { return base.Count; } } /// @@ -260,143 +251,6 @@ namespace System.Threading.Tasks return true; } - /// Attempts to peek at an item in the queue. - /// The peeked item. - /// true if an item could be peeked; otherwise, false. - public bool TryPeek(out T result) - { - Segment segment = m_head; - var array = segment.m_array; - int first = segment.m_state.m_first; // local copy to avoid multiple volatile reads - - // Fast path: there's obviously data available in the current segment - if (first != segment.m_state.m_lastCopy) - { - result = array[first]; - return true; - } - // Slow path: there may not be data available in the current segment - else return TryPeekSlow(ref segment, ref array, out result); - } - - /// Attempts to peek at an item in the queue. - /// The array from which the item is peeked. - /// The segment from which the item is peeked. - /// The peeked item. - /// true if an item could be peeked; otherwise, false. - private bool TryPeekSlow(ref Segment segment, ref T[] array, out T result) - { - Contract.Requires(segment != null, "Expected a non-null segment."); - Contract.Requires(array != null, "Expected a non-null item array."); - - if (segment.m_state.m_last != segment.m_state.m_lastCopy) - { - segment.m_state.m_lastCopy = segment.m_state.m_last; - return TryPeek(out result); // will only recur once for this peek operation - } - - if (segment.m_next != null && segment.m_state.m_first == segment.m_state.m_last) - { - segment = segment.m_next; - array = segment.m_array; - m_head = segment; - } - - var first = segment.m_state.m_first; // local copy to avoid extraneous volatile reads - - if (first == segment.m_state.m_last) - { - result = default(T); - return false; - } - - result = array[first]; - return true; - } - - /// Attempts to dequeue an item from the queue. - /// The predicate that must return true for the item to be dequeued. If null, all items implicitly return true. - /// The dequeued item. - /// true if an item could be dequeued; otherwise, false. - public bool TryDequeueIf(Predicate predicate, out T result) - { - Segment segment = m_head; - var array = segment.m_array; - int first = segment.m_state.m_first; // local copy to avoid multiple volatile reads - - // Fast path: there's obviously data available in the current segment - if (first != segment.m_state.m_lastCopy) - { - result = array[first]; - if (predicate == null || predicate(result)) - { - array[first] = default(T); // Clear the slot to release the element - segment.m_state.m_first = (first + 1) & (array.Length - 1); - return true; - } - else - { - result = default(T); - return false; - } - } - // Slow path: there may not be data available in the current segment - else return TryDequeueIfSlow(predicate, ref segment, ref array, out result); - } - - /// Attempts to dequeue an item from the queue. - /// The predicate that must return true for the item to be dequeued. If null, all items implicitly return true. - /// The array from which the item was dequeued. - /// The segment from which the item was dequeued. - /// The dequeued item. - /// true if an item could be dequeued; otherwise, false. - private bool TryDequeueIfSlow(Predicate predicate, ref Segment segment, ref T[] array, out T result) - { - Contract.Requires(segment != null, "Expected a non-null segment."); - Contract.Requires(array != null, "Expected a non-null item array."); - - if (segment.m_state.m_last != segment.m_state.m_lastCopy) - { - segment.m_state.m_lastCopy = segment.m_state.m_last; - return TryDequeueIf(predicate, out result); // will only recur once for this dequeue operation - } - - if (segment.m_next != null && segment.m_state.m_first == segment.m_state.m_last) - { - segment = segment.m_next; - array = segment.m_array; - m_head = segment; - } - - var first = segment.m_state.m_first; // local copy to avoid extraneous volatile reads - - if (first == segment.m_state.m_last) - { - result = default(T); - return false; - } - - result = array[first]; - if (predicate == null || predicate(result)) - { - array[first] = default(T); // Clear the slot to release the element - segment.m_state.m_first = (first + 1) & (segment.m_array.Length - 1); - segment.m_state.m_lastCopy = segment.m_state.m_last; // Refresh m_lastCopy to ensure that m_first has not passed m_lastCopy - return true; - } - else - { - result = default(T); - return false; - } - } - - public void Clear() - { - T ignored; - while (TryDequeue(out ignored)) ; - } - /// Gets whether the collection is currently empty. /// WARNING: This should not be used concurrently without further vetting. public bool IsEmpty @@ -452,17 +306,6 @@ namespace System.Threading.Tasks } } - /// A thread-safe way to get the number of items in the collection. May synchronize access by locking the provided synchronization object. - /// The Count is not thread safe, so we need to acquire the lock. - int IProducerConsumerQueue.GetCountSafe(object syncObj) - { - Debug.Assert(syncObj != null, "The syncObj parameter is null."); - lock (syncObj) - { - return Count; - } - } - /// A segment in the queue containing one or more items. [StructLayout(LayoutKind.Sequential)] private sealed class Segment @@ -520,23 +363,9 @@ namespace System.Threading.Tasks Contract.Requires(queue != null, "Expected a non-null queue."); m_queue = queue; } - - /// Gets the contents of the list. - [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] - public T[] Items - { - get - { - List list = new List(); - foreach (T item in m_queue) - list.Add(item); - return list.ToArray(); - } - } } } - /// A placeholder class for common padding constants and eventually routines. static class PaddingHelpers { -- cgit v1.2.3