From a29f40e073a0308bd74f0f9803a4660aa233c3ab Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Sat, 12 Mar 2022 16:39:39 -0800 Subject: "Dynamic" Mutex Allocation --- src/util/lock.c | 1 + src/util/mutex.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'src/util') 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 #include +#include #include // 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 +#include + +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; +} -- cgit v1.2.1