mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
threads: add wrapper for initializing recursive mutexes
Damn this overly verbose pthread API.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -6,4 +6,6 @@
|
||||
int mpthread_cond_timed_wait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
||||
double timeout);
|
||||
|
||||
int mpthread_mutex_init_recursive(pthread_mutex_t *mutex);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user