aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/globals.c3
-rw-r--r--src/util/lock.c1
-rw-r--r--src/util/mutex.c26
3 files changed, 30 insertions, 0 deletions
diff --git a/src/globals.c b/src/globals.c
index 29760b6..c704cb4 100644
--- a/src/globals.c
+++ b/src/globals.c
@@ -1,5 +1,6 @@
#define GLOBALS_C
#include <sys/schedule.h>
+#include <util/mutex.h>
char* os_name = "Jobbed";
#ifndef VERSION
char* os_info_v = "?";
@@ -16,6 +17,8 @@ __attribute__((section(".bss"))) unsigned int gwidth;
__attribute__((section(".bss"))) unsigned int gheight;
__attribute__((section(".bss"))) unsigned int gpitch;
__attribute__((section(".bss"))) unsigned int gisrgb;
+__attribute__((section(".bss.mutexl"))) unsigned long mutex_table[MAX_MUTEXS];
+__attribute__((section(".bss.mutexs"))) struct Mutex mutexs[MAX_MUTEXS];
// 0 - Free
// 1 - Ready
// 2 - Waiting for Mutex
diff --git a/src/util/lock.c b/src/util/lock.c
index 95f93af..eaeb5a8 100644
--- a/src/util/lock.c
+++ b/src/util/lock.c
@@ -1,5 +1,6 @@
#include <cpu.h>
#include <cpu/atomic/swap.h>
+#include <util/mutex.h>
#include <util/lock.h>
// TODO: Improve locking for system
diff --git a/src/util/mutex.c b/src/util/mutex.c
index e69de29..3171501 100644
--- a/src/util/mutex.c
+++ b/src/util/mutex.c
@@ -0,0 +1,26 @@
+#include <util/mutex.h>
+#include <globals.h>
+
+struct Mutex* create_mutex(void* addr)
+{
+ for (unsigned long m = 0; m < MAX_MUTEXS; m++) {
+ if (mutex_table[m] == 0) {
+ mutex_table[m] = (unsigned long)addr;
+ mutexs[m].pid = 0;
+ mutexs[m].addr = addr;
+ return &mutexs[m];
+ }
+ }
+ return 0;
+}
+
+unsigned char delete_mutex(struct Mutex* m)
+{
+ for (unsigned long i = 0; i < MAX_MUTEXS; i++) {
+ if (mutex_table[i] == (unsigned long)m->addr) {
+ mutex_table[i] = 0;
+ return 0;
+ }
+ }
+ return 1;
+}