From 4acbf6ae9e52a9089cdfb591d7b7d5807d9f14d6 Mon Sep 17 00:00:00 2001 From: Shengwen Cheng <shengwen1997.tw@gmail.com> Date: Tue, 28 Nov 2023 21:57:17 +0800 Subject: [PATCH] pthread_once_control: replace wait queue with list head --- include/kernel/thread.h | 2 +- kernel/kernel.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/kernel/thread.h b/include/kernel/thread.h index e8bcd8a3..c071c3e5 100644 --- a/include/kernel/thread.h +++ b/include/kernel/thread.h @@ -20,7 +20,7 @@ struct thread_attr { }; struct thread_once { - struct list_head wq; + struct list_head wait_list; bool finished; }; diff --git a/kernel/kernel.c b/kernel/kernel.c index 9032efca..02b7ef55 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -2163,7 +2163,7 @@ static void pthread_once_cleanup_handler(void) /* Wake up all waiting threads and mark once variable as complete */ struct thread_once *once_control = running_thread->once_control; once_control->finished = true; - wake_up_all(&once_control->wq); + wake_up_all(&once_control->wait_list); } static int sys_pthread_once(pthread_once_t *_once_control, @@ -2174,12 +2174,14 @@ static int sys_pthread_once(pthread_once_t *_once_control, if (once_control->finished) return 0; - if (once_control->wq.next == NULL || once_control->wq.prev == NULL) { + if (once_control->wait_list.next == NULL || + once_control->wait_list.prev == NULL) { /* The first time to execute pthread_once() */ - init_waitqueue_head(&once_control->wq); + INIT_LIST_HEAD(&once_control->wait_list); } else { /* pthread_once() is already called */ - prepare_to_wait(&once_control->wq, &running_thread->list, THREAD_WAIT); + prepare_to_wait(&once_control->wait_list, &running_thread->list, + THREAD_WAIT); return 0; }