45 pthread_mutexattr_t attr;
47 if (pthread_mutexattr_init(&attr)) {
51 pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
56 if (pthread_mutex_init(&p->
mutex, &attr)) {
71 ret = pthread_mutex_lock(&mtx->
mutex);
76 struct timespec abstime;
80 abstime.tv_nsec += (timeout_ms % 1000) * 1000000;
81 abstime.tv_sec += timeout_ms / 1000;
83 if (abstime.tv_nsec > 1000000000) {
84 abstime.tv_nsec -= 1000000000;
88 ret = pthread_mutex_timedlock(&mtx->
mutex, &abstime);
93 if (timeout_ms == 0) {
94 ret = pthread_mutex_trylock(&mtx->
mutex);
108 ret = pthread_mutex_unlock(&mtx->
mutex);
117 pthread_mutexattr_t attr;
119 if (pthread_mutexattr_init(&attr)) {
123 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
124 pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
129 if (pthread_mutex_init(&p->
mutex, &attr)) {
int clock_gettime(clockid_t clk_id, struct timespec *t)
Main PiOS header to include all the compiled in PiOS options.
bool PIOS_Mutex_Unlock(struct pios_mutex *mtx)
struct pios_mutex * PIOS_Mutex_Create(void)
struct pios_recursive_mutex * PIOS_Recursive_Mutex_Create(void)
bool PIOS_Recursive_Mutex_Lock(struct pios_recursive_mutex *mtx, uint32_t timeout_ms)
#define PIOS_Assert(test)
bool PIOS_Recursive_Mutex_Unlock(struct pios_recursive_mutex *mtx)
#define PIOS_MUTEX_TIMEOUT_MAX
bool PIOS_Mutex_Lock(struct pios_mutex *mtx, uint32_t timeout_ms)