Imported Upstream version 3.8.0

Former-commit-id: 6a76a29bd07d86e57c6c8da45c65ed5447d38a61
This commit is contained in:
Jo Shields
2014-09-04 09:07:35 +01:00
parent a575963da9
commit fe777c5c82
1062 changed files with 12460 additions and 5983 deletions

View File

@ -97,12 +97,13 @@ namespace System.Collections.Concurrent
public bool TryDequeue (out T result)
{
result = default (T);
Node oldNext = null;
bool advanced = false;
while (!advanced) {
Node oldHead = head;
Node oldTail = tail;
Node oldNext = oldHead.Next;
oldNext = oldHead.Next;
if (oldHead == head) {
// Empty case ?
@ -122,6 +123,8 @@ namespace System.Collections.Concurrent
}
}
oldNext.Value = default (T);
Interlocked.Decrement (ref count);
return true;
@ -129,14 +132,24 @@ namespace System.Collections.Concurrent
public bool TryPeek (out T result)
{
Node first = head.Next;
result = default (T);
bool update = true;
while (update)
{
Node oldHead = head;
Node oldNext = oldHead.Next;
if (first == null) {
result = default (T);
return false;
if (oldNext == null) {
result = default (T);
return false;
}
result = oldNext.Value;
//check if head has been updated
update = head != oldHead;
}
result = first.Value;
return true;
}