diff options
author | Christian Cunningham <cc@localhost> | 2022-03-12 16:39:39 -0800 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-03-12 16:39:39 -0800 |
commit | a29f40e073a0308bd74f0f9803a4660aa233c3ab (patch) | |
tree | e607ee7eed39da0e1dcf65c4eb76dd1426899f85 /src/util/mutex.c | |
parent | b62c324bde267a5a940b1d06f44f62a125aef50d (diff) |
"Dynamic" Mutex Allocation
Diffstat (limited to 'src/util/mutex.c')
-rw-r--r-- | src/util/mutex.c | 26 |
1 files changed, 26 insertions, 0 deletions
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; +} |