diff options
Diffstat (limited to 'src/playlist_vector.c')
-rw-r--r-- | src/playlist_vector.c | 65 |
1 files changed, 27 insertions, 38 deletions
diff --git a/src/playlist_vector.c b/src/playlist_vector.c index 7c1765a98..74c7bf089 100644 --- a/src/playlist_vector.c +++ b/src/playlist_vector.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2010 The Music Player Daemon Project + * Copyright (C) 2003-2011 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -19,6 +19,7 @@ #include "config.h" #include "playlist_vector.h" +#include "db_lock.h" #include <assert.h> #include <string.h> @@ -46,60 +47,48 @@ playlist_metadata_free(struct playlist_metadata *pm) } void -playlist_vector_deinit(struct playlist_vector *pv) +playlist_vector_deinit(struct list_head *pv) { assert(pv != NULL); - while (pv->head != NULL) { - struct playlist_metadata *pm = pv->head; - pv->head = pm->next; + struct playlist_metadata *pm, *n; + playlist_vector_for_each_safe(pm, n, pv) playlist_metadata_free(pm); - } } -static struct playlist_metadata ** -playlist_vector_find_p(struct playlist_vector *pv, const char *name) +struct playlist_metadata * +playlist_vector_find(struct list_head *pv, const char *name) { + assert(holding_db_lock()); assert(pv != NULL); assert(name != NULL); - struct playlist_metadata **pmp = &pv->head; - - for (;;) { - struct playlist_metadata *pm = *pmp; - if (pm == NULL) - return NULL; - + struct playlist_metadata *pm; + playlist_vector_for_each(pm, pv) if (strcmp(pm->name, name) == 0) - return pmp; + return pm; - pmp = &pm->next; - } -} - -struct playlist_metadata * -playlist_vector_find(struct playlist_vector *pv, const char *name) -{ - struct playlist_metadata **pmp = playlist_vector_find_p(pv, name); - return pmp != NULL ? *pmp : NULL; + return NULL; } void -playlist_vector_add(struct playlist_vector *pv, +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); - pm->next = pv->head; - pv->head = pm; + list_add_tail(&pm->siblings, pv); } bool -playlist_vector_update_or_add(struct playlist_vector *pv, +playlist_vector_update_or_add(struct list_head *pv, const char *name, time_t mtime) { - struct playlist_metadata **pmp = playlist_vector_find_p(pv, name); - if (pmp != NULL) { - struct playlist_metadata *pm = *pmp; + assert(holding_db_lock()); + + struct playlist_metadata *pm = playlist_vector_find(pv, name); + if (pm != NULL) { if (mtime == pm->mtime) return false; @@ -111,15 +100,15 @@ playlist_vector_update_or_add(struct playlist_vector *pv, } bool -playlist_vector_remove(struct playlist_vector *pv, const char *name) +playlist_vector_remove(struct list_head *pv, const char *name) { - struct playlist_metadata **pmp = playlist_vector_find_p(pv, name); - if (pmp == NULL) - return false; + assert(holding_db_lock()); - struct playlist_metadata *pm = *pmp; - *pmp = pm->next; + struct playlist_metadata *pm = playlist_vector_find(pv, name); + if (pm == NULL) + return false; + list_del(&pm->siblings); playlist_metadata_free(pm); return true; } |