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 <jukka.laitinen@tii.ae>
This commit is contained in:
Jukka Laitinen 2025-04-03 11:30:52 +03:00 committed by Lup Yuen Lee
parent 9967593009
commit 84cb21791f

View file

@ -29,6 +29,7 @@
#include <errno.h> #include <errno.h>
#include <nuttx/semaphore.h> #include <nuttx/semaphore.h>
#include <nuttx/atomic.h>
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
@ -64,7 +65,7 @@ int nxsem_get_value(FAR sem_t *sem, FAR int *sval)
{ {
if (sem != NULL && sval != NULL) if (sem != NULL && sval != NULL)
{ {
*sval = sem->semcount; *sval = atomic_read(NXSEM_COUNT(sem));
return OK; return OK;
} }