aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-02-13 19:25:03 +0100
committerMax Kellermann <max@duempel.org>2012-02-13 19:26:04 +0100
commit5ee3a9a9cad4436b99b56ea6336cbfa91fe7a967 (patch)
treeefe0b9748ae98f73474024b8e2100c98e2c870b4
parentdd26fa67f2c7189636e867710d3c94f93296557f (diff)
downloadmpd-5ee3a9a9cad4436b99b56ea6336cbfa91fe7a967.tar.gz
mpd-5ee3a9a9cad4436b99b56ea6336cbfa91fe7a967.tar.xz
mpd-5ee3a9a9cad4436b99b56ea6336cbfa91fe7a967.zip
playlist_vector: require database lock for all functions
-rw-r--r--src/playlist_vector.c8
-rw-r--r--src/playlist_vector.h11
-rw-r--r--src/update_db.c4
-rw-r--r--src/update_walk.c7
4 files changed, 27 insertions, 3 deletions
diff --git a/src/playlist_vector.c b/src/playlist_vector.c
index adf5b2a22..74c7bf089 100644
--- a/src/playlist_vector.c
+++ b/src/playlist_vector.c
@@ -19,6 +19,7 @@
#include "config.h"
#include "playlist_vector.h"
+#include "db_lock.h"
#include <assert.h>
#include <string.h>
@@ -58,6 +59,7 @@ playlist_vector_deinit(struct list_head *pv)
struct playlist_metadata *
playlist_vector_find(struct list_head *pv, const char *name)
{
+ assert(holding_db_lock());
assert(pv != NULL);
assert(name != NULL);
@@ -73,6 +75,8 @@ void
playlist_vector_add(struct list_head *pv,
const char *name, time_t mtime)
{
+ assert(holding_db_lock());
+
struct playlist_metadata *pm = playlist_metadata_new(name, mtime);
list_add_tail(&pm->siblings, pv);
}
@@ -81,6 +85,8 @@ bool
playlist_vector_update_or_add(struct list_head *pv,
const char *name, time_t mtime)
{
+ assert(holding_db_lock());
+
struct playlist_metadata *pm = playlist_vector_find(pv, name);
if (pm != NULL) {
if (mtime == pm->mtime)
@@ -96,6 +102,8 @@ playlist_vector_update_or_add(struct list_head *pv,
bool
playlist_vector_remove(struct list_head *pv, const char *name)
{
+ assert(holding_db_lock());
+
struct playlist_metadata *pm = playlist_vector_find(pv, name);
if (pm == NULL)
return false;
diff --git a/src/playlist_vector.h b/src/playlist_vector.h
index ae21a051f..0af6df8b4 100644
--- a/src/playlist_vector.h
+++ b/src/playlist_vector.h
@@ -49,20 +49,31 @@ struct playlist_metadata {
void
playlist_vector_deinit(struct list_head *pv);
+/**
+ * Caller must lock the #db_mutex.
+ */
struct playlist_metadata *
playlist_vector_find(struct list_head *pv, const char *name);
+/**
+ * Caller must lock the #db_mutex.
+ */
void
playlist_vector_add(struct list_head *pv,
const char *name, time_t mtime);
/**
+ * Caller must lock the #db_mutex.
+ *
* @return true if the vector or one of its items was modified
*/
bool
playlist_vector_update_or_add(struct list_head *pv,
const char *name, time_t mtime);
+/**
+ * Caller must lock the #db_mutex.
+ */
bool
playlist_vector_remove(struct list_head *pv, const char *name);
diff --git a/src/update_db.c b/src/update_db.c
index c6636de1a..8982a53e2 100644
--- a/src/update_db.c
+++ b/src/update_db.c
@@ -96,9 +96,9 @@ delete_name_in(struct directory *parent, const char *name)
modified = true;
}
- db_unlock();
-
playlist_vector_remove(&parent->playlists, name);
+ db_unlock();
+
return modified;
}
diff --git a/src/update_walk.c b/src/update_walk.c
index ba92cbc48..003807da6 100644
--- a/src/update_walk.c
+++ b/src/update_walk.c
@@ -162,8 +162,11 @@ removeDeletedFromDirectory(struct directory *directory)
struct playlist_metadata *pm, *np;
directory_for_each_playlist_safe(pm, np, directory) {
- if (!directory_child_is_regular(directory, pm->name))
+ if (!directory_child_is_regular(directory, pm->name)) {
+ db_lock();
playlist_vector_remove(&directory->playlists, pm->name);
+ db_unlock();
+ }
}
}
@@ -467,9 +470,11 @@ update_regular_file(struct directory *directory,
#endif
} else if (playlist_suffix_supported(suffix)) {
+ db_lock();
if (playlist_vector_update_or_add(&directory->playlists, name,
st->st_mtime))
modified = true;
+ db_unlock();
}
}