1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| | #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 the lock, +1 for the congestion */
int current = a_cas(l, 0, INT_MIN + 1);
if (!current) return;
__lock_slow(l, current);
}
static inline void __unlock_fast(volatile int *l)
{
/* Check l[0] to see if we are multi-threaded. */
if (l[0] < 0) {
if (a_fetch_add(l, -(INT_MIN + 1)) != (INT_MIN + 1)) {
__wake(l, 1, 1);
}
}
}
|