-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlock.c
More file actions
38 lines (31 loc) · 693 Bytes
/
lock.c
File metadata and controls
38 lines (31 loc) · 693 Bytes
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
#include "lock.h"
#include "uart.h"
#ifdef CLOSE_INT_ENABLE
static void acquire_spin_lock()
{
w_mstatus(r_mstatus() & ~MSTATUS_MIE);
}
static void release_spin_lock()
{
w_mstatus(r_mstatus() | MSTATUS_MIE);
}
#else
void init_spin_lock(spin_lock_t *lock)
{
lock->locked = 0;
}
void acquire_spin_lock(spin_lock_t *lock)
{
while (__sync_lock_test_and_set(&lock->locked, 1) != 0);
}
void release_spin_lock(spin_lock_t *lock)
{
if (lock->locked == 0) {
return ;
} else if (lock->locked == 1) {
__sync_lock_test_and_set(&lock->locked, 0);
} else {
uart_puts("WARN:Try to release a spin-lock with an unusual locked-value\n");
}
}
#endif