playlist: Fix mutex initialization

This is a one-time thing; make sure it doesn't happen more than once.

Change-Id: Ic42f48e5714dff2906c252ecd091989d2d6e5a86
This commit is contained in:
Aidan MacDonald 2023-01-21 21:05:02 +00:00
parent 2a40d42012
commit ce52d0c870
2 changed files with 12 additions and 9 deletions

View file

@ -592,13 +592,6 @@ static void empty_playlist_unlocked(struct playlist_info* playlist, bool resume)
} }
} }
/* initializes the mutex for a new playlist and sets it as empty */
static void initalize_new_playlist(struct playlist_info* playlist, bool resume)
{
mutex_init(&(playlist->mutex));
empty_playlist_unlocked(playlist, resume);
}
/* /*
* Returns absolute path of track * Returns absolute path of track
* *
@ -668,7 +661,7 @@ static void new_playlist_unlocked(struct playlist_info* playlist,
const char *fileused = file; const char *fileused = file;
const char *dirused = dir; const char *dirused = dir;
initalize_new_playlist(playlist, false); empty_playlist_unlocked(playlist, false);
if (!fileused) if (!fileused)
{ {
@ -2079,6 +2072,7 @@ void playlist_init(void)
{ {
int handle; int handle;
struct playlist_info* playlist = &current_playlist; struct playlist_info* playlist = &current_playlist;
mutex_init(&playlist->mutex);
strmemccpy(playlist->control_filename, PLAYLIST_CONTROL_FILE, strmemccpy(playlist->control_filename, PLAYLIST_CONTROL_FILE,
sizeof(playlist->control_filename)); sizeof(playlist->control_filename));
@ -2089,7 +2083,7 @@ void playlist_init(void)
handle = core_alloc_ex(playlist->max_playlist_size * sizeof(*playlist->indices), &ops); handle = core_alloc_ex(playlist->max_playlist_size * sizeof(*playlist->indices), &ops);
playlist->indices = core_get_data(handle); playlist->indices = core_get_data(handle);
initalize_new_playlist(playlist, true); empty_playlist_unlocked(playlist, true);
#ifdef HAVE_DIRCACHE #ifdef HAVE_DIRCACHE
playlist->dcfrefs_handle = core_alloc( playlist->dcfrefs_handle = core_alloc(

View file

@ -119,6 +119,7 @@ static struct playlist_viewer viewer;
/* Used when viewing playlists on disk */ /* Used when viewing playlists on disk */
static struct playlist_info temp_playlist; static struct playlist_info temp_playlist;
static bool temp_playlist_init = false;
static bool dirty = false; static bool dirty = false;
@ -365,6 +366,14 @@ static bool playlist_viewer_init(struct playlist_viewer * viewer,
char *index_buffer = NULL; char *index_buffer = NULL;
ssize_t index_buffer_size = 0; ssize_t index_buffer_size = 0;
/* Initialize temp playlist
* TODO - move this to playlist.c */
if (!temp_playlist_init)
{
mutex_init(&temp_playlist.mutex);
temp_playlist_init = true;
}
viewer->playlist = &temp_playlist; viewer->playlist = &temp_playlist;
/* Separate directory from filename */ /* Separate directory from filename */