From: acevest Date: Sat, 20 May 2023 06:26:13 +0000 (+0800) Subject: 删除semaphore __down里的enable_irq和disable_irq X-Git-Url: http://zhaoyanbai.com/repos/dnssec-signzone.html?a=commitdiff_plain;h=ab1891c62f00e4a3728888446f8bb6fbbe5bd087;p=kernel.git 删除semaphore __down里的enable_irq和disable_irq --- diff --git a/include/system.h b/include/system.h index f30d7cc..3e56a3e 100644 --- a/include/system.h +++ b/include/system.h @@ -267,7 +267,7 @@ void init_task_entry(); void disk_task_entry(); void user_task_entry(); -extern int irq_reenter; +extern volatile int irq_reenter; #endif #endif //_SYSTEM_H diff --git a/kernel/semaphore.c b/kernel/semaphore.c index 857dca1..55360e8 100644 --- a/kernel/semaphore.c +++ b/kernel/semaphore.c @@ -21,7 +21,7 @@ typedef struct semaphore_waiter { #define DECLARE_SEMAPHORE_WAITER(name, task) semaphore_waiter_t name = SEMAPHORE_WAITER_INITIALIZER(name, task) -void __down(semaphore_t *s) { +volatile void __down(semaphore_t *s) { task_union *task = current; DECLARE_SEMAPHORE_WAITER(waiter, task); list_add_tail(&waiter.list, &s->wait_list); @@ -29,21 +29,18 @@ void __down(semaphore_t *s) { while (true) { task->state = TASK_WAIT; - enable_irq(); - schedule(); - disable_irq(); - if (waiter.up) { break; } } } -void down(semaphore_t *s) { +volatile void down(semaphore_t *s) { unsigned long iflags; irq_save(iflags); + if (likely(s->cnt > 0)) { s->cnt--; } else { @@ -53,7 +50,7 @@ void down(semaphore_t *s) { irq_restore(iflags); } -void __up(semaphore_t *s) { +volatile void __up(semaphore_t *s) { semaphore_waiter_t *waiter = list_first_entry(&s->wait_list, semaphore_waiter_t, list); list_del(&waiter->list); waiter->up = 1; @@ -61,7 +58,7 @@ void __up(semaphore_t *s) { waiter->task->state = TASK_READY; } -void up(semaphore_t *s) { +volatile void up(semaphore_t *s) { unsigned long iflags; irq_save(iflags); diff --git a/kernel/system.c b/kernel/system.c index 48dded1..56183d9 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -192,4 +192,4 @@ Desc gdt[NGDT] __attribute__((__aligned__(8))); char gdtr[6] __attribute__((__aligned__(4))); char idtr[6] __attribute__((__aligned__(4))); -int irq_reenter = 0x00; \ No newline at end of file +volatile int irq_reenter = 0x00; \ No newline at end of file diff --git a/kernel/wait.c b/kernel/wait.c index a94aca8..a89f2f2 100644 --- a/kernel/wait.c +++ b/kernel/wait.c @@ -12,23 +12,23 @@ #include #include -void init_wait_queue_head(wait_queue_head_t *wqh) { INIT_LIST_HEAD(&wqh->task_list); } +volatile void init_wait_queue_head(wait_queue_head_t *wqh) { INIT_LIST_HEAD(&wqh->task_list); } -void add_wait_queue(wait_queue_head_t *head, wait_queue_t *wq) { +volatile void add_wait_queue(wait_queue_head_t *head, wait_queue_t *wq) { unsigned long flags; irq_save(flags); list_add_tail(&wq->task_list, &head->task_list); irq_restore(flags); } -void del_wait_queue(wait_queue_head_t *head, wait_queue_t *wq) { +volatile void del_wait_queue(wait_queue_head_t *head, wait_queue_t *wq) { unsigned long flags; irq_save(flags); list_del(&wq->task_list); irq_restore(flags); } -void prepare_to_wait(wait_queue_head_t *head, wait_queue_t *wq, unsigned int state) { +volatile 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)) { @@ -38,7 +38,7 @@ void prepare_to_wait(wait_queue_head_t *head, wait_queue_t *wq, unsigned int sta irq_restore(flags); } -void __end_wait(wait_queue_head_t *head, wait_queue_t *wq) { +volatile void __end_wait(wait_queue_head_t *head, wait_queue_t *wq) { set_current_state(TASK_READY); unsigned long flags; irq_save(flags); @@ -46,7 +46,7 @@ void __end_wait(wait_queue_head_t *head, wait_queue_t *wq) { irq_restore(flags); } -void sleep_on(wait_queue_head_t *head) { +volatile void sleep_on(wait_queue_head_t *head) { DECLARE_WAIT_QUEUE(wait, current); unsigned long flags; @@ -59,9 +59,12 @@ void sleep_on(wait_queue_head_t *head) { irq_restore(flags); schedule(); + + // wake_up操作会把wait从heat链表上删除 + // 所以这里就不用做什么了 } -void __wake_up(wait_queue_head_t *head, int nr) { +volatile void __wake_up(wait_queue_head_t *head, int nr) { unsigned long flags; wait_queue_t *p, *tmp; irq_save(flags); @@ -80,7 +83,7 @@ void __wake_up(wait_queue_head_t *head, int nr) { // no schedule() here. } -void wake_up(wait_queue_head_t *head) { __wake_up(head, 1); } +volatile void wake_up(wait_queue_head_t *head) { __wake_up(head, 1); } #include DECLARE_WAIT_QUEUE_HEAD(debug_wq);