7 #define STEAL_THRESHOLD 100000
9 void lock(lock_t
*_lock
)
11 while (_lock
->lock
== LOCKED
) {
14 if (_lock
->contention
> STEAL_THRESHOLD
) {
15 pid_t pid
= _lock
->owner
;
17 if (pid_alive(pid
) == FALSE
) {
18 output(0, "[%d] more than %d attempts to get lock. pid %d looks dead, stealing.\n",
19 getpid(), STEAL_THRESHOLD
, pid
);
26 _lock
->contention
= 0;
28 _lock
->owner
= getpid();
31 void unlock(lock_t
*_lock
)
33 asm volatile("" ::: "memory");
34 _lock
->contention
= 0;
35 _lock
->lock
= UNLOCKED
;