diff options
Diffstat (limited to 'kernel/util')
-rw-r--r-- | kernel/util/mutex.c | 14 |
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; |