[rhythmbox] rhythmdb: fix deadlock between db load and rhythmdb_add_uri_with_types



commit a2ead52faa45a37f28dff1e94cad5f0dadd28129
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sun Nov 4 10:13:34 2012 +1000

    rhythmdb: fix deadlock between db load and rhythmdb_add_uri_with_types
    
    These took the entry lock (within rhythmdb-tree) and the stat lock
    (within rhythmdb) in different orders, and so would deadlock if they
    were unlucky enough to happen at the same time.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=678032

 rhythmdb/rhythmdb.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/rhythmdb/rhythmdb.c b/rhythmdb/rhythmdb.c
index 0d331b4..766c160 100644
--- a/rhythmdb/rhythmdb.c
+++ b/rhythmdb/rhythmdb.c
@@ -2982,9 +2982,17 @@ rhythmdb_add_uri_with_types (RhythmDB *db,
 			     RhythmDBEntryType *ignore_type,
 			     RhythmDBEntryType *error_type)
 {
+	RhythmDBEntry *entry;
+
 	rb_debug ("queueing stat for \"%s\"", uri);
 	g_assert (uri && *uri);
 
+	/* keep this outside the stat mutex, as there are other code
+	 * paths that take the stat mutex while already holding the
+	 * entry mutex.
+	 */
+	entry = rhythmdb_entry_lookup_by_location (db, uri);
+
 	/*
 	 * before the action thread is started, we queue up stat actions,
 	 * as we're still creating and running queries, as well as loading
@@ -3008,11 +3016,7 @@ rhythmdb_add_uri_with_types (RhythmDB *db,
 
 		g_async_queue_push (db->priv->action_queue, action);
 	} else {
-		RhythmDBEntry *entry;
-
-		entry = rhythmdb_entry_lookup_by_location (db, uri);
 		rhythmdb_add_to_stat_list (db, uri, entry, type, ignore_type, error_type);
-
 		g_mutex_unlock (&db->priv->stat_mutex);
 	}
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]