From 21fd6cd2f5539b4182c54ef5b6676f518ae7a1ca Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 8 Jan 2014 18:07:04 -0700 Subject: [PATCH] Use recursive mutex for user sources and displays - Using a recursive mutex fixes issues where objects need to enter the main libobs sources mutex while already within the mutex in the same thread. Otherwise it would keep getting locked on itself on destruction. --- libobs/obs.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libobs/obs.c b/libobs/obs.c index 0ac5be98e..01f141425 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -225,15 +225,25 @@ static void obs_free_audio(void) static bool obs_init_data(void) { struct obs_data *data = &obs->data; + pthread_mutexattr_t attr; + bool success = false; pthread_mutex_init_value(&obs->data.displays_mutex); - if (pthread_mutex_init(&data->sources_mutex, NULL) != 0) - return false; - if (pthread_mutex_init(&data->displays_mutex, NULL) != 0) + if (pthread_mutexattr_init(&attr) != 0) return false; + if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) + goto fail; + if (pthread_mutex_init(&data->sources_mutex, &attr) != 0) + goto fail; + if (pthread_mutex_init(&data->displays_mutex, &attr) != 0) + goto fail; - return true; + success = true; + +fail: + pthread_mutexattr_destroy(&attr); + return success; } static void obs_free_data(void)