1570af302Sopenharmony_ci#include "pthread_impl.h" 2570af302Sopenharmony_ci 3570af302Sopenharmony_civoid __wait(volatile int *addr, volatile int *waiters, int val, int priv) 4570af302Sopenharmony_ci{ 5570af302Sopenharmony_ci int spins=100; 6570af302Sopenharmony_ci if (priv) priv = FUTEX_PRIVATE; 7570af302Sopenharmony_ci while (spins-- && (!waiters || !*waiters)) { 8570af302Sopenharmony_ci if (*addr==val) a_spin(); 9570af302Sopenharmony_ci else return; 10570af302Sopenharmony_ci } 11570af302Sopenharmony_ci if (waiters) a_inc(waiters); 12570af302Sopenharmony_ci while (*addr==val) { 13570af302Sopenharmony_ci#ifdef __LITEOS_A__ 14570af302Sopenharmony_ci __syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0xffffffffu) != -ENOSYS 15570af302Sopenharmony_ci || __syscall(SYS_futex, addr, FUTEX_WAIT, val, 0xffffffffu); 16570af302Sopenharmony_ci#else 17570af302Sopenharmony_ci __syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS 18570af302Sopenharmony_ci || __syscall(SYS_futex, addr, FUTEX_WAIT, val, 0); 19570af302Sopenharmony_ci#endif 20570af302Sopenharmony_ci } 21570af302Sopenharmony_ci if (waiters) a_dec(waiters); 22570af302Sopenharmony_ci} 23