#include "pthread_impl.h" static inline void __lock_fast(volatile int *l) { extern void __lock_slow(volatile int*, int); if (!libc.threads_minus_1) return; /* fast path: INT_MIN for holding the lock, +1 to count this thread in the critical section. */ int current = a_cas(l, 0, INT_MIN + 1); if (!current) return; __lock_slow(l, current); } static inline void __unlock_fast(volatile int *l) { /* We have to check if l[0] had been touched at all. */ if (l[0] < 0) { if (a_fetch_add(l, -(INT_MIN + 1)) != (INT_MIN + 1)) { __wake(l, 1, 1); } } } static inline void __unlock_requeue_fast(volatile int *l, volatile int *r, int shared) { extern void __unlock_requeue_slow(volatile int*, volatile int*, int); /* We have to check if l[0] had been touched at all. */ if (l[0] < 0 && (a_fetch_add(l, -(INT_MIN + 1)) != (INT_MIN + 1))) __unlock_requeue_slow(l, r, shared); }