diff --git a/src/platforms/posix/px4_layer/px4_sem.cpp b/src/platforms/posix/px4_layer/px4_sem.cpp index c938389de4..ebf0e9cd51 100644 --- a/src/platforms/posix/px4_layer/px4_sem.cpp +++ b/src/platforms/posix/px4_layer/px4_sem.cpp @@ -85,6 +85,16 @@ int px4_sem_post(px4_sem_t *s) return 0; } +int px4_sem_getvalue(px4_sem_t *s) +{ + int val; + pthread_mutex_lock(&(s->lock)); + val = s->value; + pthread_mutex_unlock(&(s->lock)); + + return val; +} + int px4_sem_destroy(px4_sem_t *s) { pthread_mutex_lock(&(s->lock)); diff --git a/src/platforms/px4_posix.h b/src/platforms/px4_posix.h index e2d0143a0e..3c138e5a70 100644 --- a/src/platforms/px4_posix.h +++ b/src/platforms/px4_posix.h @@ -64,6 +64,7 @@ typedef struct __EXPORT int px4_sem_init(px4_sem_t *s, int pshared, unsigned value); __EXPORT int px4_sem_wait(px4_sem_t *s); __EXPORT int px4_sem_post(px4_sem_t *s); +__EXPORT int px4_sem_getvalue(px4_sem_t *s); __EXPORT int px4_sem_destroy(px4_sem_t *s); __END_DECLS @@ -75,6 +76,7 @@ typedef px4_sem_t sem_t #define px4_sem_init _GLOBAL sem_init #define px4_sem_wait _GLOBAL sem_wait #define px4_sem_post _GLOBAL px4_sem_post +#define px4_sem_getvalue _GLOBAL px4_sem_getvalue #define px4_sem_destroy _GLOBAL sem_destroy