diff --git a/sys/include/sema.h b/sys/include/sema.h index 416afbbbffea..4bbdf85cd04b 100644 --- a/sys/include/sema.h +++ b/sys/include/sema.h @@ -97,6 +97,18 @@ void sema_create(sema_t *sema, unsigned int value); */ void sema_destroy(sema_t *sema); +/** + * @brief Get a semaphore's current value + * + * @param[in] sema A semaphore. + * + * @return the current value of the semaphore + */ +static inline unsigned sema_get_value(const sema_t *sema) +{ + return sema->value; +} + /** * @brief Wait for a semaphore, blocking or non-blocking. * diff --git a/sys/posix/include/semaphore.h b/sys/posix/include/semaphore.h index 7205679dfa31..5340bb80f3a8 100644 --- a/sys/posix/include/semaphore.h +++ b/sys/posix/include/semaphore.h @@ -283,7 +283,7 @@ static inline int sem_trywait(sem_t *sem) static inline int sem_getvalue(sem_t *sem, int *sval) { if (sem != NULL) { - *sval = (int)sem->value; + *sval = (int)sema_get_value((sema_t *)sem); return 0; } errno = EINVAL;