aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2021-12-04 18:00:23 -0700
committerChristian Cunningham <cc@localhost>2021-12-04 18:00:23 -0700
commit51af35ffc632f7979fecc609445af8378466d405 (patch)
treeb13f7fb24718d7efc1e7066d9835f85416d13a55 /src/util
parentbaac108e68f8861b01b118e97b149caa26a22e58 (diff)
Created basic Mutex
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mutex.c20
-rw-r--r--src/util/mutex.h15
2 files changed, 35 insertions, 0 deletions
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;
+}
diff --git a/src/util/mutex.h b/src/util/mutex.h
new file mode 100644
index 0000000..8c9a097
--- /dev/null
+++ b/src/util/mutex.h
@@ -0,0 +1,15 @@
+#ifndef SYS_MUTEX_H
+#define SYS_MUTEX_H
+
+#define NULL_PID 0
+#define SCHED_PID 1
+
+struct Mutex {
+ unsigned long* addr;
+ unsigned long pid;
+};
+
+unsigned char lock_mutex(struct Mutex*, unsigned long);
+unsigned char release_mutex(struct Mutex*, unsigned long);
+
+#endif