mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
kernel: use circular lists in various places
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <kernel/init.h>
|
||||
#include <kernel/mm.h>
|
||||
#include <list.h>
|
||||
#include <semaphore.h>
|
||||
@@ -94,7 +95,7 @@ static int wait_on_bucket(futex_bucket_t *bucket, uintptr_t key, size_t timeoutu
|
||||
else if (state == ENTRY_STATE_TIMEOUT)
|
||||
error = ETIMEDOUT;
|
||||
|
||||
list_remove(&bucket->list, &entry.list_node);
|
||||
list_remove(&entry.list_node);
|
||||
|
||||
MUTEX_RELEASE(&bucket->mutex);
|
||||
|
||||
@@ -180,3 +181,10 @@ syscallret_t syscall_futex(context_t *, uint32_t *futexp, int op, uint32_t value
|
||||
mm_unlock_and_release_page(physical);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void futex_init(void) {
|
||||
for (size_t i = 0; i < BUCKET_COUNT; ++i)
|
||||
list_init(&buckets[i].list);
|
||||
}
|
||||
|
||||
INIT_ROUTINE_DEFINE(futex, INIT_ROUTINE_FLAGS_NONE, futex_init, bsp_early);
|
||||
|
||||
@@ -32,11 +32,11 @@ static bool work_active(work_queue_t *wq, work_t *work) {
|
||||
}
|
||||
|
||||
static void wake_waiters(work_queue_t *wq, work_t *work) {
|
||||
list_for_each_safe (&wq->waiter_list, node) {
|
||||
list_for_each_safe (&wq->waiter_list, node, next) {
|
||||
work_waiter_t *ww = (work_waiter_t *)node;
|
||||
|
||||
if (ww->work == work) {
|
||||
list_remove(&wq->waiter_list, &ww->list_node);
|
||||
list_remove(&ww->list_node);
|
||||
sched_wakeup(ww->thread, SCHED_WAKEUP_REASON_NORMAL);
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ static void worker() {
|
||||
|
||||
ipl = spinlock_acquire_raise_ipl(&wq->lock, wq->lock_ipl);
|
||||
wake_waiters(wq, work);
|
||||
list_remove(&wq->active_list, &aw.list_node);
|
||||
list_remove(&aw.list_node);
|
||||
spinlock_release_lower_ipl(&wq->lock, ipl);
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ int work_dequeue(work_queue_t *wq, work_t *work) {
|
||||
goto leave;
|
||||
|
||||
wake_waiters(wq, work);
|
||||
list_remove(&wq->work_list, &work->list_node);
|
||||
list_remove(&work->list_node);
|
||||
work->pending = 0;
|
||||
|
||||
leave:
|
||||
|
||||
Reference in New Issue
Block a user