You've already forked linux-packaging-mono
Imported Upstream version 5.16.0.100
Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
parent
0a9828183b
commit
7d7f676260
@ -79,6 +79,9 @@ namespace System.Threading
|
||||
// A pre-completed task with Result==true
|
||||
private readonly static Task<bool> s_trueTask =
|
||||
new Task<bool>(false, true, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default(CancellationToken));
|
||||
// A pre-completed task with Result==false
|
||||
private readonly static Task<bool> s_falseTask =
|
||||
new Task<bool>(false, false, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default(CancellationToken));
|
||||
|
||||
// No maximum constant
|
||||
private const int NO_MAXIMUM = Int32.MaxValue;
|
||||
@ -323,6 +326,13 @@ namespace System.Threading
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// Perf: Check the stack timeout parameter before checking the volatile count
|
||||
if (millisecondsTimeout == 0 && m_currentCount == 0)
|
||||
{
|
||||
// Pessimistic fail fast, check volatile count outside lock (only when timeout is zero!)
|
||||
return false;
|
||||
}
|
||||
|
||||
uint startTime = 0;
|
||||
if (millisecondsTimeout != Timeout.Infinite && millisecondsTimeout > 0)
|
||||
{
|
||||
@ -620,6 +630,11 @@ namespace System.Threading
|
||||
--m_currentCount;
|
||||
if (m_waitHandle != null && m_currentCount == 0) m_waitHandle.Reset();
|
||||
return s_trueTask;
|
||||
}
|
||||
else if (millisecondsTimeout == 0)
|
||||
{
|
||||
// No counts, if timeout is zero fail fast
|
||||
return s_falseTask;
|
||||
}
|
||||
// If there aren't, create and return a task to the caller.
|
||||
// The task will be completed either when they've successfully acquired
|
||||
|
Reference in New Issue
Block a user