Add fast bitset, inode search to EXT2
diff --git a/src/kernel/sync.c b/src/kernel/sync.c
index 2bac9e4..0db5022 100644
--- a/src/kernel/sync.c
+++ b/src/kernel/sync.c
@@ -2,10 +2,9 @@
#include <alloc.h>
#include <task.h>
#include <sys.h>
-#include "syscall.h"
+#include <log.h>
#define SM_PER_LIST 1024
-#define SM_MAX_WAITING 64
struct sm_task
{
@@ -50,7 +49,20 @@
return 0;
}
-void sm_unsafe_wait(struct semaphore *sm)
+static struct semaphore *sm_from_id(semaphore_t sm)
+{
+ struct sm_list *first = sm_first;
+
+ while (sm >= SM_PER_LIST)
+ {
+ first = first->next;
+ sm -= SM_PER_LIST;
+ }
+
+ return &first->semaphores[sm];
+}
+
+static void sm_unsafe_wait(struct semaphore *sm)
{
sm->sm--;
@@ -60,6 +72,8 @@
// This will be quick, so just use a spinlock
sl_acquire(sm->task_lock);
+ kprintf(INFO "Semaphore waiting\n");
+
struct sm_task *task = malloc(sizeof(struct sm_task));
task->next = NULL;
@@ -84,7 +98,7 @@
// Otherwise there's nobody else waiting, just go ahead
}
-void sm_unsafe_signal(struct semaphore *sm)
+static void sm_unsafe_signal(struct semaphore *sm)
{
sm->sm++;
@@ -137,6 +151,18 @@
return num;
}
+void sm_wait(semaphore_t sm)
+{
+ sm_unsafe_wait(sm_from_id(sm));
+}
+
+void sm_signal(semaphore_t sm)
+{
+ sm_unsafe_signal(sm_from_id(sm));
+}
+
+
+
void init_sync()
{
}