diff options
author | Jo Shields <directhex@apebox.org> | 2014-02-19 22:12:43 +0000 |
---|---|---|
committer | Jo Shields <directhex@apebox.org> | 2014-02-19 22:12:43 +0000 |
commit | 9972bf87b4f27d9c8f358ef8414ac1ab957a2f0f (patch) | |
tree | 5bb230c1d698659115f918e243c1d4b0aa4c7f51 /mcs/class/System/System.Collections.Concurrent/BlockingCollection.cs | |
parent | d0a215f5626219ff7927f576588a777e5331c7be (diff) | |
download | mono-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/BlockingCollection.cs')
-rw-r--r-- | mcs/class/System/System.Collections.Concurrent/BlockingCollection.cs | 44 |
1 files changed, 30 insertions, 14 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; } |