32 #define SEMAPHORE_MAGIC 0x616d6553
49 pthread_mutexattr_t attr;
51 if (pthread_mutexattr_init(&attr)) {
55 pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
57 if (pthread_mutex_init(&s->
mutex, &attr)) {
61 if (pthread_cond_init(&s->
cond, NULL)) {
76 struct timespec abstime;
81 abstime.tv_nsec += (timeout_ms % 1000) * 1000000;
82 abstime.tv_sec += timeout_ms / 1000;
84 if (abstime.tv_nsec > 1000000000) {
85 abstime.tv_nsec -= 1000000000;
90 pthread_mutex_lock(&sema->
mutex);
92 while (!sema->
given) {
94 if (pthread_cond_timedwait(&sema->
cond,
95 &sema->
mutex, &abstime)) {
96 pthread_mutex_unlock(&sema->
mutex);
100 pthread_cond_wait(&sema->
cond, &sema->
mutex);
106 pthread_mutex_unlock(&sema->
mutex);
117 pthread_mutex_lock(&sema->
mutex);
123 pthread_cond_signal(&sema->
cond);
125 pthread_mutex_unlock(&sema->
mutex);
int clock_gettime(clockid_t clk_id, struct timespec *t)
Main PiOS header to include all the compiled in PiOS options.
void * PIOS_malloc(size_t size)
bool PIOS_Semaphore_Give_FromISR(struct pios_semaphore *sema, bool *woken)
#define PIOS_QUEUE_TIMEOUT_MAX
struct pios_semaphore * PIOS_Semaphore_Create(void)
Creates a binary semaphore.
bool PIOS_Semaphore_Take_FromISR(struct pios_semaphore *sema, bool *woken)
bool PIOS_Semaphore_Give(struct pios_semaphore *sema)
Gives binary semaphore.
bool PIOS_Semaphore_Take(struct pios_semaphore *sema, uint32_t timeout_ms)
Takes binary semaphore.
#define PIOS_Assert(test)