aboutsummaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-01-31 22:12:14 +0100
committerMax Kellermann <max@duempel.org>2012-02-02 18:06:33 +0100
commitef5cf40fa6d3e2f50ad916be8e5bd99affe7d2e3 (patch)
treebffd4ea35f30f96e8dc8d1ac74184bd4dab5d5d6 /src/db
parent837bd79b20d4b9b8525a42999a9d1911f8980aa4 (diff)
downloadmpd-ef5cf40fa6d3e2f50ad916be8e5bd99affe7d2e3.tar.gz
mpd-ef5cf40fa6d3e2f50ad916be8e5bd99affe7d2e3.tar.xz
mpd-ef5cf40fa6d3e2f50ad916be8e5bd99affe7d2e3.zip
directory: require the caller to lock the db_mutex
Reduce the number of lock/unlock cycles, and make database handling safer.
Diffstat (limited to 'src/db')
-rw-r--r--src/db/simple_db_plugin.c13
1 files changed, 11 insertions, 2 deletions
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");