aboutsummaryrefslogtreecommitdiff
path: root/src/util/lock.c
blob: 6b048f4fbb0b6f1621e6c1232ad996879ececbda (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
#include <cpu.h>
#include <cpu/atomic/swap.h>
#include <lib/kmem.h>
#include <util/lock.h>

void lock(struct Lock* l)
{
	unsigned long mode = getmode() & 0x1F;
	if (mode == 0x10) {
		sys1(SYS_LOCK, l);
	} else {
		atm_lock(CORE0_PID, (unsigned long*)l);
	}
}

void unlock(struct Lock* l)
{
	unsigned long mode = getmode() & 0x1F;
	if (mode == 0x10) {
		sys1(SYS_UNLOCK, l);
	} else {
		atm_release((unsigned long*)l);
	}
}

struct Lock* create_lock(void)
{
	struct Lock* l = (struct Lock*)kmalloc(sizeof(struct Lock));
	l->pid = 0;
	return l;
}