Skip to content

Commit

Permalink
Use SpinWait.SpinUntil to replace busy wait
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsuciu committed Sep 9, 2024
1 parent cc30e82 commit dcdfdf3
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions Libraries/Opc.Ua.PubSub/IntervalRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,12 @@ private async Task ProcessAsync()
nowTick = HiResClock.Ticks;
if (nowTick < nextPublishTick)
{
while (HiResClock.Ticks < nextPublishTick)
{
// Busy-wait and avoid overhead of Task.Delay for verry small wait times
}
SpinWait.SpinUntil(() => HiResClock.Ticks >= nextPublishTick);
}
}
else if (sleepCycle >= 0 && sleepCycle <= 16)
{
while (HiResClock.Ticks < nextPublishTick)
{
// Busy-wait and avoid overhead of Task.Delay for verry small wait times
}
SpinWait.SpinUntil(() => HiResClock.Ticks >= nextPublishTick);
}

lock (m_lock)
Expand Down

0 comments on commit dcdfdf3

Please sign in to comment.