split out the page dirtying to its own file.
[trinity.git] / locks.c
bloba5386e959c4151a586258db387a0abd1a0e2cd34
1 #include <signal.h>
2 #include <unistd.h>
3 #include "locks.h"
4 #include "log.h"
5 #include "pids.h"
7 #define STEAL_THRESHOLD 100000
9 void lock(lock_t *_lock)
11 while (_lock->lock == LOCKED) {
12 _lock->contention++;
13 usleep(1);
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);
20 goto steal;
25 steal:
26 _lock->contention = 0;
27 _lock->lock = LOCKED;
28 _lock->owner = getpid();
31 void unlock(lock_t *_lock)
33 _lock->contention = 0;
34 _lock->lock = UNLOCKED;
35 _lock->owner = 0;