threads: add wrapper for initializing recursive mutexes

Damn this overly verbose pthread API.
This commit is contained in:
wm4
2014-01-31 19:50:25 +01:00
parent 2305ffcaba
commit a17be5576f
4 changed files with 17 additions and 10 deletions

View File

@@ -55,3 +55,14 @@ int mpthread_cond_timed_wait(pthread_cond_t *cond, pthread_mutex_t *mutex,
timespec_add_seconds(&ts, timeout);
return pthread_cond_timedwait(cond, mutex, &ts);
}
// Helper to reduce boiler plate.
int mpthread_mutex_init_recursive(pthread_mutex_t *mutex)
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
int r = pthread_mutex_init(mutex, &attr);
pthread_mutexattr_destroy(&attr);
return r;
}