blob: ade270f18e002f0b8bd7d002635d9735a16b9deb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include <asm.h>
#include <spinlock.h>
void
initlock(struct spinlock *l)
{
l->locked = 0;
}
void
acquire(struct spinlock *l)
{
sie_disable();
if (l->locked)
return;
while (__sync_lock_test_and_set(&l->locked, 1))
;
__sync_synchronize();
}
void
release(struct spinlock *l)
{
sie_disable(); // avoid deadlock
if (l->locked)
return; // interrupts are still disabled, what to do here?
/* fence */
__sync_synchronize();
__sync_lock_release(&l->locked);
sie_enable();
}
|