From 51af35ffc632f7979fecc609445af8378466d405 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Sat, 4 Dec 2021 18:00:23 -0700 Subject: Created basic Mutex --- src/util/mutex.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/util/mutex.c (limited to 'src/util/mutex.c') diff --git a/src/util/mutex.c b/src/util/mutex.c new file mode 100644 index 0000000..86ffcf5 --- /dev/null +++ b/src/util/mutex.c @@ -0,0 +1,20 @@ +#include "../util/mutex.h" + +unsigned char lock_mutex(struct Mutex* m, unsigned long pid) { + if (m->pid == NULL_PID) { + m->pid = 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; + return 0; + } + return 1; +} -- cgit v1.2.1