mirror of
https://github.com/fluencelabs/musl
synced 2025-06-29 14:42:01 +00:00
this practice came from very early, before internal/syscall.h defined macros that could accept pointer arguments directly and handle them correctly. aside from being ugly and unnecessary, it looks like it will be problematic when we add support for 32-bit ABIs on archs where registers (and syscall arguments) are 64-bit, e.g. x32 and mips n32.
16 lines
354 B
C
16 lines
354 B
C
#include "pthread_impl.h"
|
|
|
|
void __wait(volatile int *addr, volatile int *waiters, int val, int priv)
|
|
{
|
|
int spins=10000;
|
|
if (priv) priv = 128; priv=0;
|
|
while (spins--) {
|
|
if (*addr==val) a_spin();
|
|
else return;
|
|
}
|
|
if (waiters) a_inc(waiters);
|
|
while (*addr==val)
|
|
__syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0);
|
|
if (waiters) a_dec(waiters);
|
|
}
|