2
* Copyright (C) 2003-2011 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
#include "config.h" /* must be first for large file support */
21
#include "update_remove.h"
22
#include "event_pipe.h"
29
#include "song_sticker.h"
36
static const struct song *removed_song;
38
static GMutex *remove_mutex;
39
static GCond *remove_cond;
42
* Safely remove a song from the database. This must be done in the
43
* main task, to be sure that there is no pointer left to it.
46
song_remove_event(void)
50
assert(removed_song != NULL);
52
uri = song_get_uri(removed_song);
53
g_message("removing %s", uri);
57
/* if the song has a sticker, remove it */
58
if (sticker_enabled())
59
sticker_song_delete(removed_song);
62
playlist_delete_song(&g_playlist, global_player_control, removed_song);
64
/* clear "removed_song" and send signal to update thread */
65
g_mutex_lock(remove_mutex);
67
g_cond_signal(remove_cond);
68
g_mutex_unlock(remove_mutex);
72
update_remove_global_init(void)
74
remove_mutex = g_mutex_new();
75
remove_cond = g_cond_new();
77
event_pipe_register(PIPE_EVENT_DELETE, song_remove_event);
81
update_remove_global_finish(void)
83
g_mutex_free(remove_mutex);
84
g_cond_free(remove_cond);
88
update_remove_song(const struct song *song)
90
assert(removed_song == NULL);
94
event_pipe_emit(PIPE_EVENT_DELETE);
96
g_mutex_lock(remove_mutex);
98
while (removed_song != NULL)
99
g_cond_wait(remove_cond, remove_mutex);
101
g_mutex_unlock(remove_mutex);