summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Threading/Tasks/ProducerConsumerQueues.cs
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2017-02-10 20:35:12 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2017-02-10 20:35:12 +0900
commit4b11dc566a5bbfa1378d6266525c281b028abcc8 (patch)
treeb48831a898906734f8884d08b6e18f1144ee2b82 /src/mscorlib/src/System/Threading/Tasks/ProducerConsumerQueues.cs
parentdb20f3f1bb8595633a7e16c8900fd401a453a6b5 (diff)
downloadcoreclr-4b11dc566a5bbfa1378d6266525c281b028abcc8.tar.gz
coreclr-4b11dc566a5bbfa1378d6266525c281b028abcc8.tar.bz2
coreclr-4b11dc566a5bbfa1378d6266525c281b028abcc8.zip
Imported Upstream version 1.0.0.9910upstream/1.0.0.9910
Diffstat (limited to 'src/mscorlib/src/System/Threading/Tasks/ProducerConsumerQueues.cs')
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/ProducerConsumerQueues.cs171
1 files changed, 0 insertions, 171 deletions
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
/// <summary>Gets the number of items in the collection.</summary>
/// <remarks>In many implementations, this method will not be thread-safe.</remarks>
int Count { get; }
-
- /// <summary>A thread-safe way to get the number of items in the collection. May synchronize access by locking the provided synchronization object.</summary>
- /// <param name="syncObj">The sync object used to lock</param>
- /// <returns>The collection count</returns>
- int GetCountSafe(object syncObj);
}
/// <summary>
@@ -80,10 +75,6 @@ namespace System.Threading.Tasks
/// <summary>Gets the number of items in the collection.</summary>
int IProducerConsumerQueue<T>.Count { get { return base.Count; } }
-
- /// <summary>A thread-safe way to get the number of items in the collection. May synchronize access by locking the provided synchronization object.</summary>
- /// <remarks>ConcurrentQueue.Count is thread safe, no need to acquire the lock.</remarks>
- int IProducerConsumerQueue<T>.GetCountSafe(object syncObj) { return base.Count; }
}
/// <summary>
@@ -260,143 +251,6 @@ namespace System.Threading.Tasks
return true;
}
- /// <summary>Attempts to peek at an item in the queue.</summary>
- /// <param name="result">The peeked item.</param>
- /// <returns>true if an item could be peeked; otherwise, false.</returns>
- 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);
- }
-
- /// <summary>Attempts to peek at an item in the queue.</summary>
- /// <param name="array">The array from which the item is peeked.</param>
- /// <param name="segment">The segment from which the item is peeked.</param>
- /// <param name="result">The peeked item.</param>
- /// <returns>true if an item could be peeked; otherwise, false.</returns>
- 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;
- }
-
- /// <summary>Attempts to dequeue an item from the queue.</summary>
- /// <param name="predicate">The predicate that must return true for the item to be dequeued. If null, all items implicitly return true.</param>
- /// <param name="result">The dequeued item.</param>
- /// <returns>true if an item could be dequeued; otherwise, false.</returns>
- public bool TryDequeueIf(Predicate<T> 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);
- }
-
- /// <summary>Attempts to dequeue an item from the queue.</summary>
- /// <param name="predicate">The predicate that must return true for the item to be dequeued. If null, all items implicitly return true.</param>
- /// <param name="array">The array from which the item was dequeued.</param>
- /// <param name="segment">The segment from which the item was dequeued.</param>
- /// <param name="result">The dequeued item.</param>
- /// <returns>true if an item could be dequeued; otherwise, false.</returns>
- private bool TryDequeueIfSlow(Predicate<T> 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)) ;
- }
-
/// <summary>Gets whether the collection is currently empty.</summary>
/// <remarks>WARNING: This should not be used concurrently without further vetting.</remarks>
public bool IsEmpty
@@ -452,17 +306,6 @@ namespace System.Threading.Tasks
}
}
- /// <summary>A thread-safe way to get the number of items in the collection. May synchronize access by locking the provided synchronization object.</summary>
- /// <remarks>The Count is not thread safe, so we need to acquire the lock.</remarks>
- int IProducerConsumerQueue<T>.GetCountSafe(object syncObj)
- {
- Debug.Assert(syncObj != null, "The syncObj parameter is null.");
- lock (syncObj)
- {
- return Count;
- }
- }
-
/// <summary>A segment in the queue containing one or more items.</summary>
[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;
}
-
- /// <summary>Gets the contents of the list.</summary>
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public T[] Items
- {
- get
- {
- List<T> list = new List<T>();
- foreach (T item in m_queue)
- list.Add(item);
- return list.ToArray();
- }
- }
}
}
-
/// <summary>A placeholder class for common padding constants and eventually routines.</summary>
static class PaddingHelpers
{