]> Zhao Yanbai Git Server - kernel.git/commitdiff
rename __do_wait to prepare_to_wait
authoracevest <zhaoyanbai@126.com>
Thu, 18 Nov 2021 10:30:59 +0000 (18:30 +0800)
committeracevest <zhaoyanbai@126.com>
Sun, 21 Nov 2021 14:26:31 +0000 (22:26 +0800)
include/wait.h
kernel/task_disk.c
kernel/wait.c

index 616634edacb23783b1c14d128f6602db970bc240..6e9d03ca4f116e0054643c5f5785d8c1ebc9318b 100644 (file)
@@ -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)          \
index 02ca8cbd40f2ecb9268bba41a0f1f69574232089..9ed8f0cfd9132d0b49b539bd7c2d4d5ab42b1a33 100644 (file)
@@ -8,9 +8,10 @@
  */
 
 #include <sched.h>
+#include <semaphore.h>
 #include <wait.h>
-#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++;
     }
 }
index bc59197437ee6e59887df8f2d051a70e35885637..51afc3eef4db7c27b6272172734d2891d1ff36d7 100644 (file)
@@ -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)) {