update_remove: use plain GCond instead of notify
GMutex/GCond guarantee that the access to removed_song is protected.
This commit is contained in:
parent
77d3b5e8f1
commit
1025f0be91
|
@ -19,7 +19,6 @@
|
|||
|
||||
#include "config.h" /* must be first for large file support */
|
||||
#include "update_internal.h"
|
||||
#include "notify.h"
|
||||
#include "event_pipe.h"
|
||||
#include "song.h"
|
||||
#include "playlist.h"
|
||||
|
@ -36,7 +35,8 @@
|
|||
|
||||
static const struct song *removed_song;
|
||||
|
||||
static struct notify remove_notify;
|
||||
static GMutex *remove_mutex;
|
||||
static GCond *remove_cond;
|
||||
|
||||
/**
|
||||
* Safely remove a song from the database. This must be done in the
|
||||
|
@ -60,15 +60,19 @@ song_remove_event(void)
|
|||
#endif
|
||||
|
||||
playlist_delete_song(&g_playlist, global_player_control, removed_song);
|
||||
removed_song = NULL;
|
||||
|
||||
notify_signal(&remove_notify);
|
||||
/* clear "removed_song" and send signal to update thread */
|
||||
g_mutex_lock(remove_mutex);
|
||||
removed_song = NULL;
|
||||
g_cond_signal(remove_cond);
|
||||
g_mutex_unlock(remove_mutex);
|
||||
}
|
||||
|
||||
void
|
||||
update_remove_global_init(void)
|
||||
{
|
||||
notify_init(&remove_notify);
|
||||
remove_mutex = g_mutex_new();
|
||||
remove_cond = g_cond_new();
|
||||
|
||||
event_pipe_register(PIPE_EVENT_DELETE, song_remove_event);
|
||||
}
|
||||
|
@ -76,7 +80,8 @@ update_remove_global_init(void)
|
|||
void
|
||||
update_remove_global_finish(void)
|
||||
{
|
||||
notify_deinit(&remove_notify);
|
||||
g_mutex_free(remove_mutex);
|
||||
g_cond_free(remove_cond);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -88,8 +93,10 @@ update_remove_song(const struct song *song)
|
|||
|
||||
event_pipe_emit(PIPE_EVENT_DELETE);
|
||||
|
||||
do {
|
||||
notify_wait(&remove_notify);
|
||||
} while (removed_song != NULL);
|
||||
g_mutex_lock(remove_mutex);
|
||||
|
||||
while (removed_song != NULL)
|
||||
g_cond_wait(remove_cond, remove_mutex);
|
||||
|
||||
g_mutex_unlock(remove_mutex);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue