Skip to content

Commit

Permalink
Optimize common path
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-safar committed Aug 19, 2013
1 parent 88dadaa commit 1fe2472
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mcs/class/corlib/System.Threading/CancellationToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public CancellationTokenRegistration Register (Action<object> callback, object s

public void ThrowIfCancellationRequested ()
{
if (Source.IsCancellationRequested)
if (source != null && source.IsCancellationRequested)
throw new OperationCanceledException (this);
}

Expand Down
4 changes: 2 additions & 2 deletions mcs/class/corlib/System.Threading/ManualResetEventSlim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ public bool Wait (int millisecondsTimeout, CancellationToken cancellationToken)
SpinWait wait = new SpinWait ();

while (!IsSet) {
cancellationToken.ThrowIfCancellationRequested ();

if (wait.Count < spinCount) {
wait.SpinOnce ();
continue;
Expand All @@ -174,6 +172,8 @@ public bool Wait (int millisecondsTimeout, CancellationToken cancellationToken)
break;
}

cancellationToken.ThrowIfCancellationRequested ();

if (IsSet)
return true;

Expand Down

0 comments on commit 1fe2472

Please sign in to comment.