]> Zhao Yanbai Git Server - kernel.git/commitdiff
fix semaphore
authoracevest <zhaoyanbai@126.com>
Wed, 17 Nov 2021 15:18:49 +0000 (23:18 +0800)
committeracevest <zhaoyanbai@126.com>
Wed, 17 Nov 2021 15:18:49 +0000 (23:18 +0800)
kernel/semaphore.c

index 04c0a69f3a05059128ed01cd4dff3f6642328bbf..4dd314a94a043aca7170e25147803f807c4dfcf3 100644 (file)
@@ -26,22 +26,23 @@ void __down(semaphore_t *s) {
     DECLARE_SEMAPHORE_WAITER(waiter, task);
     list_add_tail(&waiter.list, &s->wait_list);
 
-    // while(true)
-    {
+    while (true) {
         task->state = TASK_WAIT;
 
         enable_irq();
+
         schedule();
+
         disable_irq();
 
-        if (waiter.up)
-            ;  // break;
+        if (waiter.up) {
+            break;
+        }
     }
 }
 
 void down(semaphore_t *s) {
     unsigned long iflags;
-
     irq_save(iflags);
 
     if (likely(s->cnt > 0)) {
@@ -63,8 +64,8 @@ void __up(semaphore_t *s) {
 
 void up(semaphore_t *s) {
     unsigned long iflags;
-
     irq_save(iflags);
+
     if (likely(list_empty(&s->wait_list))) {
         s->cnt++;
     } else {