From d05754a98e6f7c877ecfd9515b0e24bc4ed45021 Mon Sep 17 00:00:00 2001 From: TXuian <1163589503@qq.com> Date: Wed, 29 May 2024 16:22:23 +0800 Subject: [PATCH] Fix a semaphore.c bug --- Ubiquitous/XiZi_AIoT/services/app/Makefile | 2 +- Ubiquitous/XiZi_AIoT/services/app/test_semaphore.c | 1 + Ubiquitous/XiZi_AIoT/softkernel/task/semaphore.c | 9 +++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Ubiquitous/XiZi_AIoT/services/app/Makefile b/Ubiquitous/XiZi_AIoT/services/app/Makefile index a7d4c0684..54616c791 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/app/Makefile @@ -35,7 +35,7 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \ ifeq ($(BOARD), imx6q-sabrelite) all: init test_fault simple_client simple_server shell fs_server semaphore_server test_semaphore test_ipc_null test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server readme.txt | bin else -all: init test_fault simple_client simple_server shell fs_server test_ipc_null test_thread test_semaphore readme.txt | bin +all: init test_fault simple_client simple_server shell fs_server semaphore_server test_ipc_null test_thread test_semaphore readme.txt | bin endif ../tools/mkfs/mkfs ./fs.img $^ @mv $(filter-out readme.txt, $^) bin diff --git a/Ubiquitous/XiZi_AIoT/services/app/test_semaphore.c b/Ubiquitous/XiZi_AIoT/services/app/test_semaphore.c index a682ec11b..6492fd35e 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/test_semaphore.c +++ b/Ubiquitous/XiZi_AIoT/services/app/test_semaphore.c @@ -66,6 +66,7 @@ int main(int argc, char** argv) printf("test thread sum after %d signal: 0x%x\n", NR_THREADS, sum); + semaphore_free(sem_id); exit(0); return 0; } diff --git a/Ubiquitous/XiZi_AIoT/softkernel/task/semaphore.c b/Ubiquitous/XiZi_AIoT/softkernel/task/semaphore.c index 575e1aa7d..f1c5b5443 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/task/semaphore.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/task/semaphore.c @@ -35,10 +35,10 @@ static inline struct ksemaphore* ksemaphore_get_by_id(struct XiziSemaphorePool* DOUBLE_LIST_FOR_EACH_ENTRY(sem, &sem_pool->sem_list_guard, sem_list_node) { if (sem->id == sem_id) { - break; + return sem; } } - return sem; + return NULL; } int ksemaphore_alloc(struct XiziSemaphorePool* sem_pool, int val) @@ -102,8 +102,9 @@ bool ksemaphore_signal(struct XiziSemaphorePool* sem_pool, uint32_t sem_id) if (sem->val < 0) { if (!IS_DOUBLE_LIST_EMPTY(&sem->wait_list_guard)) { - assert(sem->wait_list_guard.next != NULL); - xizi_task_manager.task_unblock(CONTAINER_OF(sem->wait_list_guard.next, struct Thread, node)); + struct Thread* thd = CONTAINER_OF(sem->wait_list_guard.next, struct Thread, node); + assert(thd != NULL && thd->state == BLOCKED); + xizi_task_manager.task_unblock(thd); } }