From ef5cf40fa6d3e2f50ad916be8e5bd99affe7d2e3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 31 Jan 2012 22:12:14 +0100 Subject: directory: require the caller to lock the db_mutex Reduce the number of lock/unlock cycles, and make database handling safer. --- src/db/simple_db_plugin.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/db') diff --git a/src/db/simple_db_plugin.c b/src/db/simple_db_plugin.c index 816f4503b..f11090828 100644 --- a/src/db/simple_db_plugin.c +++ b/src/db/simple_db_plugin.c @@ -59,7 +59,11 @@ simple_db_lookup_directory(const struct simple_db *db, const char *uri) assert(db->root != NULL); assert(uri != NULL); - return directory_lookup_directory(db->root, uri); + db_lock(); + struct directory *directory = + directory_lookup_directory(db->root, uri); + db_unlock(); + return directory; } static struct db * @@ -236,7 +240,9 @@ simple_db_get_song(struct db *_db, const char *uri, GError **error_r) assert(db->root != NULL); + db_lock(); struct song *song = directory_lookup_song(db->root, uri); + db_unlock(); if (song == NULL) g_set_error(error_r, db_quark(), DB_NOT_FOUND, "No such song: %s", uri); @@ -301,13 +307,16 @@ simple_db_save(struct db *_db, GError **error_r) struct simple_db *db = (struct simple_db *)_db; struct directory *music_root = db->root; + db_lock(); + g_debug("removing empty directories from DB"); directory_prune_empty(music_root); g_debug("sorting DB"); - directory_sort(music_root); + db_unlock(); + g_debug("writing DB"); FILE *fp = fopen(db->path, "w"); -- cgit v1.2.3