aboutsummaryrefslogtreecommitdiff
path: root/kernel/util
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-08-26 23:27:46 -0700
committerChristian Cunningham <cc@localhost>2022-08-26 23:27:46 -0700
commit41a7818b552aef9e6e0bf788089f6ae16ae1e421 (patch)
tree87b4010b7f24a75d497450b3d98fc4f8f667e404 /kernel/util
parent8b36a39774789cee66d84db9f0086af15cacc211 (diff)
Mutex wait queuesno-search
Diffstat (limited to 'kernel/util')
-rw-r--r--kernel/util/mutex.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/kernel/util/mutex.c b/kernel/util/mutex.c
index 997d85d..b05aee3 100644
--- a/kernel/util/mutex.c
+++ b/kernel/util/mutex.c
@@ -9,18 +9,14 @@ void mutex_init(void)
for (unsigned long m = 0; m < MAX_MUTEXS; m++) {
mutexs[m].pid = 0;
mutexs[m].addr = 0;
+ mutexs[m].locking_thread = 0;
+ mutexs[m].waiting_threads = 0;
mutex_entries[m].value = &mutexs[m];
- mutex_entries[m].entry_type = VALUE_ENTRY;
mutex_entries[m].next = &mutex_entries[m+1];
}
// Initialize Free Mutexs
- mutex_manager.free.start.value = 0;
mutex_manager.free.start.next = &mutex_entries[0];
- mutex_manager.free.start.entry_type = START_ENTRY;
- mutex_manager.free.end.value = 0;
- mutex_manager.free.end.next = &mutex_entries[MAX_MUTEXS-1];
- mutex_entries[MAX_MUTEXS-1].next = &mutex_manager.free.end;
- mutex_manager.free.end.entry_type = END_ENTRY;
+ mutex_entries[MAX_MUTEXS-1].next = 0;
}
struct Mutex* create_mutex(void* addr)
@@ -44,7 +40,8 @@ unsigned char delete_mutex(struct Mutex* m)
return 1;
struct Entry* entry = &mutex_entries[index];
// Add it to the free queue
- prepend_to_queue(entry, &mutex_manager.free);
+ push_to_queue(entry, &mutex_manager.free);
+ mutex_manager.used_mutexes--;
return 0;
}
@@ -67,6 +64,7 @@ unsigned char lock_mutex(struct Mutex* m)
if ((unsigned char) index > rthread->highest_mutex)
return 2;
sys1(SYS_LOCK, m);
+ m->locking_thread = &mutex_entries[index];
return 0;
}
return 3;