Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix % used in PerCoreLockedStacks #55959

Merged
merged 2 commits into from
Jul 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public bool TryPush(T[] array)
// Try to push on to the associated stack first. If that fails,
// round-robin through the other stacks.
LockedStack[] stacks = _perCoreStacks;
int index = Thread.GetCurrentProcessorId() % stacks.Length;
int index = (int)((uint)Thread.GetCurrentProcessorId() % (uint)s_lockedStackCount); // mod by constant in tier 1
for (int i = 0; i < stacks.Length; i++)
{
if (stacks[index].TryPush(array)) return true;
Expand All @@ -298,7 +298,7 @@ public bool TryPush(T[] array)
// Try to pop from the associated stack first. If that fails, round-robin through the other stacks.
T[]? arr;
LockedStack[] stacks = _perCoreStacks;
int index = Thread.GetCurrentProcessorId() % s_lockedStackCount; // when ProcessorCount is a power of two, the JIT can optimize this in tier 1
int index = (int)((uint)Thread.GetCurrentProcessorId() % (uint)s_lockedStackCount); // mod by constant in tier 1
for (int i = 0; i < stacks.Length; i++)
{
if ((arr = stacks[index].TryPop()) is not null) return arr;
Expand Down