Skip to content

Commit

Permalink
Don't Sleep(1) in some spin-wait loops (Fx)
Browse files Browse the repository at this point in the history
Fx counterpart to dotnet/coreclr#21722
  • Loading branch information
kouvel committed Dec 30, 2018
1 parent 151a606 commit e2280d7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ private bool TryAddWithNoTimeValidation(T item, int millisecondsTimeout, Cancell
Debug.Assert((observedAdders + 1) <= (~COMPLETE_ADDING_ON_MASK), "The number of concurrent adders thread exceeded the maximum limit.");
break;
}
spinner.SpinOnce();
spinner.SpinOnce(sleep1Threshold: -1);
}

// This outer try/finally to workaround of repeating the decrement adders code 3 times, because we should decrement the adders if:
Expand Down Expand Up @@ -1506,7 +1506,7 @@ public void CompleteAdding()
CancelWaitingProducers();
return;
}
spinner.SpinOnce();
spinner.SpinOnce(sleep1Threshold: -1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ private void PushCore(Node head, Node tail)
// Keep trying to CAS the existing head with the new node until we succeed.
do
{
spin.SpinOnce();
spin.SpinOnce(sleep1Threshold: -1);
// Reread the head and link our new node.
tail._next = _head;
}
Expand Down Expand Up @@ -645,7 +645,7 @@ private int TryPopCore(int count, out Node poppedHead)
// We failed to CAS the new head. Spin briefly and retry.
for (int i = 0; i < backoff; i++)
{
spin.SpinOnce();
spin.SpinOnce(sleep1Threshold: -1);
}

if (spin.NextSpinWillYield)
Expand Down
8 changes: 4 additions & 4 deletions src/System.Threading/src/System/Threading/Barrier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public long AddParticipants(int participantCount)
}
break;
}
spinner.SpinOnce();
spinner.SpinOnce(sleep1Threshold: -1);
}
return newPhase;
}
Expand Down Expand Up @@ -472,7 +472,7 @@ public void RemoveParticipants(int participantCount)
break;
}
}
spinner.SpinOnce();
spinner.SpinOnce(sleep1Threshold: -1);
}
}

Expand Down Expand Up @@ -674,7 +674,7 @@ public bool SignalAndWait(int millisecondsTimeout, CancellationToken cancellatio
break;
}

spinner.SpinOnce();
spinner.SpinOnce(sleep1Threshold: -1);
}

// ** Perform the real wait **
Expand Down Expand Up @@ -740,7 +740,7 @@ public bool SignalAndWait(int millisecondsTimeout, CancellationToken cancellatio
else
return false;
}
spinner.SpinOnce();
spinner.SpinOnce(sleep1Threshold: -1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/System.Threading/src/System/Threading/CountdownEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public bool Signal(int signalCount)
}

// The CAS failed. Spin briefly and try again.
spin.SpinOnce();
spin.SpinOnce(sleep1Threshold: -1);
}

// If we were the last to signal, set the event.
Expand Down Expand Up @@ -361,7 +361,7 @@ public bool TryAddCount(int signalCount)
}

// The CAS failed. Spin briefly and try again.
spin.SpinOnce();
spin.SpinOnce(sleep1Threshold: -1);
}

return true;
Expand Down

0 comments on commit e2280d7

Please sign in to comment.