From: acevest Date: Thu, 18 Nov 2021 10:30:59 +0000 (+0800) Subject: rename __do_wait to prepare_to_wait X-Git-Url: http://zhaoyanbai.com/repos/man.rndc-confgen.html?a=commitdiff_plain;h=cdecaaebb1a0d046d76442e9eb0c72cb8a548325;p=kernel.git rename __do_wait to prepare_to_wait --- diff --git a/include/wait.h b/include/wait.h index 616634e..6e9d03c 100644 --- a/include/wait.h +++ b/include/wait.h @@ -34,24 +34,27 @@ typedef struct { void init_wait_queue_head(wait_queue_head_t *wqh); void add_wait_queue(wait_queue_head_t *head, wait_queue_t *wq); void del_wait_queue(wait_queue_head_t *head, wait_queue_t *wq); -void __do_wait(wait_queue_head_t *head, wait_queue_t *wq, unsigned int state); + +// prepare_to_wait 不会调用schedule +void prepare_to_wait(wait_queue_head_t *head, wait_queue_t *wq, unsigned int state); + void __end_wait(wait_queue_head_t *head, wait_queue_t *wq); void sleep_on(wait_queue_head_t *head); void wake_up(wait_queue_head_t *head); unsigned long schedule(); -#define __wait_event(head, condition) \ - do { \ - DECLARE_WAIT_QUEUE(__wait, current); \ - while (1) { \ - __do_wait(head, &__wait, TASK_WAIT); \ - if ((condition)) { \ - break; \ - } \ - schedule(); \ - } \ - __end_wait(head, &__wait); \ +#define __wait_event(head, condition) \ + do { \ + DECLARE_WAIT_QUEUE(__wait, current); \ + while (1) { \ + prepare_to_wait(head, &__wait, TASK_WAIT); \ + if ((condition)) { \ + break; \ + } \ + schedule(); \ + } \ + __end_wait(head, &__wait); \ } while (0) #define wait_event(head, condition) \ diff --git a/kernel/task_disk.c b/kernel/task_disk.c index 02ca8cb..9ed8f0c 100644 --- a/kernel/task_disk.c +++ b/kernel/task_disk.c @@ -8,9 +8,10 @@ */ #include +#include #include -#if 0 +#if 0 typedef enum { DISK_REQ_IDENTIFY, DISK_REQ_READ, @@ -59,10 +60,20 @@ void send_disk_request() { } #endif +typedef struct { + semaphore_t sem; + list_head_t list; +} disk_request_queue_t; + +disk_request_queue_t disk_request_queue = {.sem = SEMAPHORE_INITIALIZER(disk_request_queue.sem, 0), + .list = LIST_HEAD_INIT(disk_request_queue.list)}; + +int cnt = 0; void disk_task_entry() { while (1) { - // TODO - asm("hlt;"); - // schedule(); + printk("fuck you: %d\n", cnt); + down(&disk_request_queue.sem); + printk("fuck me: %d\n", cnt); + cnt++; } } diff --git a/kernel/wait.c b/kernel/wait.c index bc59197..51afc3e 100644 --- a/kernel/wait.c +++ b/kernel/wait.c @@ -28,7 +28,7 @@ void del_wait_queue(wait_queue_head_t *head, wait_queue_t *wq) { irq_restore(flags); } -void __do_wait(wait_queue_head_t *head, wait_queue_t *wq, unsigned int state) { +void prepare_to_wait(wait_queue_head_t *head, wait_queue_t *wq, unsigned int state) { unsigned long flags; irq_save(flags); if (list_empty(&wq->task_list)) {