feat: fixed some bugs for running on real hardware
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <libk/syscall.h>
|
||||
#include <stdbool.h>
|
||||
#include <libc/kprintf.h>
|
||||
#include <libc/libc.h>
|
||||
|
||||
typedef struct lock_fifo_entry {
|
||||
uint32_t tid;
|
||||
@@ -32,6 +33,7 @@ struct spinlock {
|
||||
|
||||
semaphore_t *semaphore_create(int32_t start) {
|
||||
semaphore_t *semaphore = malloc(sizeof(semaphore_t));
|
||||
memset((uint8_t *) semaphore, 0, sizeof(semaphore_t));
|
||||
semaphore->value = start;
|
||||
return semaphore;
|
||||
}
|
||||
@@ -43,6 +45,7 @@ void semaphore_wait(semaphore_t *semaphore) {
|
||||
task_lock_acquire();
|
||||
lock_fifo_entry_t *lock = malloc(sizeof(lock_fifo_entry_t));
|
||||
lock->tid = task_get_current_tid();
|
||||
lock->next = NULL;
|
||||
if (semaphore->first_wait == NULL) {
|
||||
semaphore->first_wait = lock;
|
||||
} else {
|
||||
@@ -77,6 +80,7 @@ void semaphore_free(semaphore_t *semaphore) {
|
||||
|
||||
mutex_t *mutex_create() {
|
||||
mutex_t *mutex = malloc(sizeof(mutex_t));
|
||||
memset((uint8_t *) mutex, 0, sizeof(mutex_t));
|
||||
mutex->value = 1;
|
||||
return mutex;
|
||||
}
|
||||
@@ -88,6 +92,7 @@ void mutex_acquire(mutex_t *mutex) {
|
||||
task_lock_acquire();
|
||||
lock_fifo_entry_t *lock = malloc(sizeof(lock_fifo_entry_t));
|
||||
lock->tid = task_get_current_tid();
|
||||
lock->next = NULL;
|
||||
if (mutex->first_wait == NULL) {
|
||||
mutex->first_wait = lock;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user