initial check-in, version 0.5.0
[musl] / src / thread / __lock.c
1 #define SYSCALL_RETURN_ERRNO
2 #include "pthread_impl.h"
3
4 void __lock(volatile int *l)
5 {
6         int spins=100000;
7         /* Do not use futexes because we insist that unlocking is a simple
8          * assignment to optimize non-pathological code with no contention. */
9         while (a_xchg(l, 1))
10                 if (spins) spins--, a_spin();
11                 else syscall0(__NR_sched_yield);
12 }