libobs/util: pthread_mutex_init_recursive helper

Add helper for creating a recursive mutex because it's easy to forget to
destroy the pthread_mutexattr_t.
This commit is contained in:
jpark37 2021-08-23 21:33:51 -07:00
parent 0b70b479a1
commit b9657f6239

View file

@ -53,6 +53,22 @@ static inline void pthread_mutex_init_value(pthread_mutex_t *mutex)
*mutex = init_val;
}
static inline int pthread_mutex_init_recursive(pthread_mutex_t *mutex)
{
pthread_mutexattr_t attr;
int ret = pthread_mutexattr_init(&attr);
if (ret == 0) {
ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
if (ret == 0) {
ret = pthread_mutex_init(mutex, &attr);
}
pthread_mutexattr_destroy(&attr);
}
return ret;
}
enum os_event_type {
OS_EVENT_TYPE_AUTO,
OS_EVENT_TYPE_MANUAL,