aboutsummaryrefslogtreecommitdiff
path: root/src/util/mutex.c
blob: 9cfdf6c57f5a86ce16e6c624d4aa2370390cf5e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "../util/mutex.h"
#include "../cpu/atomic/swap.h"

unsigned char lock_mutex(struct Mutex* m, unsigned long pid) {
	if (m->pid == NULL_PID) {
		//m->pid = pid;
		atm_lock(pid, &m->pid);
		return 0;
	}
	return 1;
}

// Eventually, there will need to be a hook into the scheduling mechanism
//  that checks the currently running process and check that against the
//  mutex's pid lock
unsigned char release_mutex(struct Mutex* m, unsigned long pid) {
	if (m->pid == pid) {
		//m->pid = NULL_PID;
		atm_release(&m->pid);
		return 0;
	}
	return 1;
}