From: acevest Date: Wed, 17 Nov 2021 15:18:49 +0000 (+0800) Subject: fix semaphore X-Git-Url: http://zhaoyanbai.com/repos/nslookup.html?a=commitdiff_plain;h=dc755b1edb084a382bd7ee6b72f204c4d6795fb4;p=kernel.git fix semaphore --- diff --git a/kernel/semaphore.c b/kernel/semaphore.c index 04c0a69..4dd314a 100644 --- a/kernel/semaphore.c +++ b/kernel/semaphore.c @@ -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 {