Fix a semaphore.c bug

This commit is contained in:
TXuian 2024-05-29 16:22:23 +08:00
parent 6d4cef4358
commit d05754a98e
3 changed files with 7 additions and 5 deletions

View File

@ -35,7 +35,7 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
ifeq ($(BOARD), imx6q-sabrelite) 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 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 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 endif
../tools/mkfs/mkfs ./fs.img $^ ../tools/mkfs/mkfs ./fs.img $^
@mv $(filter-out readme.txt, $^) bin @mv $(filter-out readme.txt, $^) bin

View File

@ -66,6 +66,7 @@ int main(int argc, char** argv)
printf("test thread sum after %d signal: 0x%x\n", NR_THREADS, sum); printf("test thread sum after %d signal: 0x%x\n", NR_THREADS, sum);
semaphore_free(sem_id);
exit(0); exit(0);
return 0; return 0;
} }

View File

@ -35,11 +35,11 @@ static inline struct ksemaphore* ksemaphore_get_by_id(struct XiziSemaphorePool*
DOUBLE_LIST_FOR_EACH_ENTRY(sem, &sem_pool->sem_list_guard, sem_list_node) DOUBLE_LIST_FOR_EACH_ENTRY(sem, &sem_pool->sem_list_guard, sem_list_node)
{ {
if (sem->id == sem_id) { if (sem->id == sem_id) {
break;
}
}
return sem; return sem;
} }
}
return NULL;
}
int ksemaphore_alloc(struct XiziSemaphorePool* sem_pool, int val) 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 (sem->val < 0) {
if (!IS_DOUBLE_LIST_EMPTY(&sem->wait_list_guard)) { if (!IS_DOUBLE_LIST_EMPTY(&sem->wait_list_guard)) {
assert(sem->wait_list_guard.next != NULL); struct Thread* thd = CONTAINER_OF(sem->wait_list_guard.next, struct Thread, node);
xizi_task_manager.task_unblock(CONTAINER_OF(sem->wait_list_guard.next, struct Thread, node)); assert(thd != NULL && thd->state == BLOCKED);
xizi_task_manager.task_unblock(thd);
} }
} }