Merge pull request #15781 from haukepetersen/add_sema_getvalue

sys/sema: add sema_get_value()
This commit is contained in:
Hauke Petersen 2021-01-16 13:03:03 +01:00 committed by GitHub
commit ed2e40df63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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.
*

View File

@ -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;