From: acevest Date: Fri, 20 Oct 2023 12:43:31 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=063d870ed76acbcc6d4d286e382ae908021c4ede;p=kernel.git ... --- diff --git a/fs/buffer.c b/fs/buffer.c index a5f0777..62cd0c1 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -127,9 +127,7 @@ again: // 因为可能有的进程调用了write、read后再直接调用brelse // 虽然此时ref_count为0,但io操作标记的b->locked并未结束 // 所以需要在此等待其结束 - while (b->locked == 1) { - // 此时是不用担心wake_up在这个sleep_on之前调用 - } + wait_event(&b->waitq_lock, b->locked == 0); // 找到了 b->block = block; @@ -191,6 +189,7 @@ void init_buffer() { b->page = page; b->uptodate = 0; b->locked = 0; + init_wait_queue_head(&b->waitq_lock); list_init(&b->node); assert(NULL != b->data); diff --git a/include/buffer.h b/include/buffer.h index 8f570cc..f58b695 100644 --- a/include/buffer.h +++ b/include/buffer.h @@ -14,6 +14,7 @@ #include #include #include +#include typedef struct bbuffer { uint32_t block; // block number @@ -22,6 +23,7 @@ typedef struct bbuffer { dev_t dev; page_t *page; list_head_t node; + wait_queue_head_t waitq_lock; uint16_t block_size; // block size uint16_t uptodate : 1; uint16_t locked : 1; diff --git a/include/sched.h b/include/sched.h index ed00ce6..7bc55cc 100644 --- a/include/sched.h +++ b/include/sched.h @@ -25,8 +25,6 @@ void schedule(); -void wake_up(wait_queue_head_t *wqh); - extern task_union root_task; extern void load_cr3(task_union *tsk); diff --git a/include/semaphore.h b/include/semaphore.h index 27eb009..207341c 100644 --- a/include/semaphore.h +++ b/include/semaphore.h @@ -28,8 +28,6 @@ void semaphore_init(semaphore_t *s, unsigned int v); // 如果s->cnt == 0 会重新调度进程 volatile void down(semaphore_t *s); -// volatile bool try_down(semaphore_t *s); - // up // 只会唤醒进程,但不会立即重新调度进程 volatile void up(semaphore_t *s); diff --git a/include/task.h b/include/task.h index 1882723..795b28e 100644 --- a/include/task.h +++ b/include/task.h @@ -22,7 +22,7 @@ #include #include #include -#include +// #include enum { TASK_UNUSED, diff --git a/include/wait.h b/include/wait.h index 8f29e93..f1bf5ea 100644 --- a/include/wait.h +++ b/include/wait.h @@ -14,7 +14,7 @@ #include #include - +#include union task_union; typedef struct wait_queue_head { diff --git a/kernel/irq.c b/kernel/irq.c index ff2d265..b6f6a5b 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -75,6 +75,7 @@ void dump_irq_nr_stack() { #endif void irq_bh_handler(); +void schedule(); __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) { unsigned int irq = regs->irq;