Browse Source

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.
jp9000 11 years ago
parent
commit
21fd6cd2f5
1 changed files with 14 additions and 4 deletions
  1. 14 4
      libobs/obs.c

+ 14 - 4
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)