summaryrefslogtreecommitdiff
path: root/mcs/class/System/System.Collections.Concurrent
diff options
context:
space:
mode:
authorJo Shields <directhex@apebox.org>2014-02-19 22:12:43 +0000
committerJo Shields <directhex@apebox.org>2014-02-19 22:12:43 +0000
commit9972bf87b4f27d9c8f358ef8414ac1ab957a2f0f (patch)
tree5bb230c1d698659115f918e243c1d4b0aa4c7f51 /mcs/class/System/System.Collections.Concurrent
parentd0a215f5626219ff7927f576588a777e5331c7be (diff)
downloadmono-upstream/3.2.8+dfsg.tar.gz
Imported Upstream version 3.2.8+dfsgupstream/3.2.8+dfsg
Diffstat (limited to 'mcs/class/System/System.Collections.Concurrent')
-rw-r--r--mcs/class/System/System.Collections.Concurrent/BlockingCollection.cs44
-rw-r--r--mcs/class/System/System.Collections.Concurrent/ConcurrentBag.cs10
2 files changed, 35 insertions, 19 deletions
diff --git a/mcs/class/System/System.Collections.Concurrent/BlockingCollection.cs b/mcs/class/System/System.Collections.Concurrent/BlockingCollection.cs
index 26dc84a078..cc7e04ecdd 100644
--- a/mcs/class/System/System.Collections.Concurrent/BlockingCollection.cs
+++ b/mcs/class/System/System.Collections.Concurrent/BlockingCollection.cs
@@ -370,13 +370,19 @@ namespace System.Collections.Concurrent
{
item = default (T);
CheckArray (collections);
- int index = 0;
- foreach (var coll in collections) {
- try {
- item = coll.Take ();
- return index;
- } catch {}
- index++;
+ WaitHandle[] wait_table = null;
+ while (true) {
+ int index = 0;
+ for (int i = 0; i < collections.Length; ++i) {
+ if (collections [i].TryTake (out item))
+ return i;
+ }
+ if (wait_table == null) {
+ wait_table = new WaitHandle [collections.Length];
+ for (int i = 0; i < collections.Length; ++i)
+ wait_table [i] = collections [i].mreRemove.WaitHandle;
+ }
+ WaitHandle.WaitAny (wait_table);
}
return -1;
}
@@ -385,14 +391,24 @@ namespace System.Collections.Concurrent
{
item = default (T);
CheckArray (collections);
- int index = 0;
- foreach (var coll in collections) {
- try {
- item = coll.Take (cancellationToken);
- return index;
- } catch {}
- index++;
+ WaitHandle[] wait_table = null;
+ while (true) {
+ int index = 0;
+ for (int i = 0; i < collections.Length; ++i) {
+ if (collections [i].TryTake (out item))
+ return i;
+ }
+ cancellationToken.ThrowIfCancellationRequested ();
+ if (wait_table == null) {
+ wait_table = new WaitHandle [collections.Length + 1];
+ for (int i = 0; i < collections.Length; ++i)
+ wait_table [i] = collections [i].mreRemove.WaitHandle;
+ wait_table [collections.Length] = cancellationToken.WaitHandle;
+ }
+ WaitHandle.WaitAny (wait_table);
+ cancellationToken.ThrowIfCancellationRequested ();
}
+
return -1;
}
diff --git a/mcs/class/System/System.Collections.Concurrent/ConcurrentBag.cs b/mcs/class/System/System.Collections.Concurrent/ConcurrentBag.cs
index 5b4cbfcf1a..cd063347c6 100644
--- a/mcs/class/System/System.Collections.Concurrent/ConcurrentBag.cs
+++ b/mcs/class/System/System.Collections.Concurrent/ConcurrentBag.cs
@@ -65,6 +65,7 @@ namespace System.Collections.Concurrent
int index;
CyclicDeque<T> bag = GetBag (out index);
bag.PushBottom (item);
+ staging.TryAdd (index, bag);
AddHint (index);
Interlocked.Increment (ref count);
}
@@ -88,6 +89,7 @@ namespace System.Collections.Concurrent
if (bag == null || bag.PopBottom (out result) != PopResult.Succeed) {
var self = bag;
+ ret = false;
foreach (var other in staging) {
// Try to retrieve something based on a hint
ret = TryGetHint (out hintIndex) && (bag = container[hintIndex]).PopTop (out result) == PopResult.Succeed;
@@ -129,6 +131,7 @@ namespace System.Collections.Concurrent
if (bag == null || !bag.PeekBottom (out result)) {
var self = bag;
+ ret = false;
foreach (var other in staging) {
// Try to retrieve something based on a hint
ret = TryGetHint (out hintIndex) && container[hintIndex].PeekTop (out result);
@@ -264,10 +267,7 @@ namespace System.Collections.Concurrent
if (container.TryGetValue (index, out value))
return value;
- var bag = createBag ? container.GetOrAdd (index, new CyclicDeque<T> ()) : null;
- if (bag != null)
- staging.TryAdd (index, bag);
- return bag;
+ return createBag ? container.GetOrAdd (index, new CyclicDeque<T> ()) : null;
}
void TidyBag (int index, CyclicDeque<T> bag)
@@ -279,4 +279,4 @@ namespace System.Collections.Concurrent
}
}
}
-#endif \ No newline at end of file
+#endif