diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-07 03:10:13 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-07 03:10:13 -0700 |
commit | 38b5be3be82d09342640fa13a64ebd09a7d4a341 (patch) | |
tree | 6c723a2008cea9afe43cb7de071e6e387b139175 /src/song.c | |
parent | e0aca2dbf9ce1ed3db295f2c4345b231c11d6c64 (diff) | |
parent | 19c6f1ee92cf6514e885def44f7deb9d225de4dc (diff) | |
download | mpd-38b5be3be82d09342640fa13a64ebd09a7d4a341.tar.gz mpd-38b5be3be82d09342640fa13a64ebd09a7d4a341.tar.xz mpd-38b5be3be82d09342640fa13a64ebd09a7d4a341.zip |
Merge branch 'ew/update-thrsafe'
* ew/update-thrsafe:
directory: serialize song deletes from playlist during update
directory: use songvec_for_each for iterators
dbUtils: more cleanups
song: Add song_print_url_x
dbUtils/directory: traverseAllIn forEachSong returns -1 on error
songvec: lock traversals for thread-safe updates/reads
song: add print_song_info_x for iterators tha pass void *
songvec: add songvec_for_each iterator
song: replace printSong* with song_print_*
Assert if we don't have song or song->url set
Diffstat (limited to '')
-rw-r--r-- | src/song.c | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/src/song.c b/src/song.c index ab98963ad..c9301386d 100644 --- a/src/song.c +++ b/src/song.c @@ -31,8 +31,13 @@ static Song * song_alloc(const char *url, Directory *parent) { - size_t urllen = strlen(url); - Song *song = xmalloc(sizeof(Song) + urllen); + size_t urllen; + Song *song; + + assert(url); + urllen = strlen(url); + assert(urllen); + song = xmalloc(sizeof(Song) + urllen); song->tag = NULL; memcpy(song->url, url, urllen + 1); @@ -44,6 +49,7 @@ static Song * song_alloc(const char *url, Directory *parent) Song *newSong(const char *url, Directory * parentDir) { Song *song; + assert(*url); if (strchr(url, '\n')) { DEBUG("newSong: '%s' is not a valid uri\n", url); @@ -73,12 +79,6 @@ Song *newSong(const char *url, Directory * parentDir) return song; } -void freeSong(Song * song) -{ - deleteASongFromPlaylist(song); - freeJustSong(song); -} - void freeJustSong(Song * song) { if (song->tag) @@ -86,24 +86,34 @@ void freeJustSong(Song * song) free(song); } -void printSongUrl(int fd, Song * song) +ssize_t song_print_url(Song *song, int fd) { - if (song->parentDir && song->parentDir->path) { - fdprintf(fd, "%s%s/%s\n", SONG_FILE, - getDirectoryPath(song->parentDir), song->url); - } else { - fdprintf(fd, "%s%s\n", SONG_FILE, song->url); - } + if (song->parentDir && song->parentDir->path) + return fdprintf(fd, "%s%s/%s\n", SONG_FILE, + getDirectoryPath(song->parentDir), song->url); + return fdprintf(fd, "%s%s\n", SONG_FILE, song->url); } -int printSongInfo(int fd, Song * song) +ssize_t song_print_info(Song *song, int fd) { - printSongUrl(fd, song); + ssize_t ret = song_print_url(song, fd); + if (ret < 0) + return ret; if (song->tag) tag_print(fd, song->tag); - return 0; + return ret; +} + +int song_print_info_x(Song * song, void *data) +{ + return song_print_info(song, (int)(size_t)data); +} + +int song_print_url_x(Song * song, void *data) +{ + return song_print_url(song, (int)(size_t)data); } static void insertSongIntoList(struct songvec *sv, Song *newsong) |