From 84cb21791face87ba8633b03582e9f4d4bc9bb18 Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Thu, 3 Apr 2025 11:30:52 +0300 Subject: [PATCH] libc/semaphore: Read semaphore value by using NXSEM_COUNT macro We should not access semaphore internals directly outside sched/semaphore. Just read it via the NXSEM_COUNT macro provided. Signed-off-by: Jukka Laitinen --- libs/libc/semaphore/sem_getvalue.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/libc/semaphore/sem_getvalue.c b/libs/libc/semaphore/sem_getvalue.c index 194f5fa1ef..14706cea05 100644 --- a/libs/libc/semaphore/sem_getvalue.c +++ b/libs/libc/semaphore/sem_getvalue.c @@ -29,6 +29,7 @@ #include #include +#include /**************************************************************************** * Public Functions @@ -64,7 +65,7 @@ int nxsem_get_value(FAR sem_t *sem, FAR int *sval) { if (sem != NULL && sval != NULL) { - *sval = sem->semcount; + *sval = atomic_read(NXSEM_COUNT(sem)); return OK; }