Skip to content

Commit 9174591

Browse files
committed
Remove do-while loops from Linux/macOS wait operations
Previously, the wait functions on Linux (futex) and macOS (ULockWait) were called in a do-while loop, repeatedly checking the condition and waiting. This commit removes the loops, so the wait operation is now performed only once per call, simplifying the logic and potentially improving efficiency.
1 parent c0122b7 commit 9174591

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

Hexa.NET.Utilities/WaitOnAddressHelper.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,15 @@ public static void Wait(ref TValue address, in TValue compare)
202202
}
203203
else if (IsLinux)
204204
{
205-
do
206-
{
207-
var slot = GetWaitTableSlot(pAddress);
208-
var val = AtomicRead(slot);
209-
Syscall(SYS_futex, slot, (void*)FUTEX_WAIT, (void*)(nuint)val, null, null, null);
210-
} while (AtomicRead(pAddress) == compare);
205+
var slot = GetWaitTableSlot(pAddress);
206+
var val = AtomicRead(slot);
207+
Syscall(SYS_futex, slot, (void*)FUTEX_WAIT, (void*)(nuint)val, null, null, null);
211208
}
212209
else if (IsMacOS)
213210
{
214-
do
215-
{
216-
var slot = GetWaitTableSlot(pAddress);
217-
uint val = AtomicRead(slot);
218-
_ = ULockWait(UL_COMPARE_AND_WAIT | ULF_NO_ERRNO, slot, val, 0);
219-
} while (AtomicRead(pAddress) == compare);
211+
var slot = GetWaitTableSlot(pAddress);
212+
uint val = AtomicRead(slot);
213+
_ = ULockWait(UL_COMPARE_AND_WAIT | ULF_NO_ERRNO, slot, val, 0);
220214
}
221215
else
222216
{

0 commit comments

Comments
 (0)