From 2042a2ae1a92386b3aff22c9518432e498fe4aee Mon Sep 17 00:00:00 2001 From: Oleksiy Yakovenko Date: Sat, 18 Nov 2023 11:07:23 +0100 Subject: [PATCH] covermanager: threadsafe shared instance --- plugins/gtkui/covermanager/covermanager.c | 9 +++++---- plugins/gtkui/covermanager/covermanager.h | 3 +++ plugins/gtkui/gtkui.c | 10 ++++++---- src/playlist.c | 4 +++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/plugins/gtkui/covermanager/covermanager.c b/plugins/gtkui/covermanager/covermanager.c index a0f3cf3902..75c8ac4229 100644 --- a/plugins/gtkui/covermanager/covermanager.c +++ b/plugins/gtkui/covermanager/covermanager.c @@ -309,13 +309,14 @@ _cover_loaded_callback (int error, ddb_cover_query_t *query, ddb_cover_info_t *c covermanager_t * covermanager_shared (void) { - // FIXME: this is not thread-safe - if (_shared == NULL) { - _shared = covermanager_new (); - } return _shared; } +void +covermanager_shared_init (void) { + _shared = covermanager_new (); +} + void covermanager_shared_free (void) { if (_shared != NULL) { diff --git a/plugins/gtkui/covermanager/covermanager.h b/plugins/gtkui/covermanager/covermanager.h index 55e5b61358..f7f35689b6 100644 --- a/plugins/gtkui/covermanager/covermanager.h +++ b/plugins/gtkui/covermanager/covermanager.h @@ -38,6 +38,9 @@ typedef void (^covermanager_completion_block_t) (GdkPixbuf *img); covermanager_t * covermanager_shared (void); +void +covermanager_shared_init (void); + void covermanager_shared_free (void); diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index e12e726afb..90b1923f75 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -1566,10 +1566,6 @@ gtkui_mainwin_free (void) { deadbeef->unlisten_file_added (fileadded_listener_id); deadbeef->unlisten_file_add_beginend (fileadd_beginend_listener_id); - covermanager_terminate (covermanager_shared ()); - // FIXME: can't do this, since artwork holds non-refcounted references to it - // covermanager_shared_free (); - w_free (); if (refresh_timeout) { @@ -1770,6 +1766,8 @@ gtkui_start (void) { gtk_disable_setlocale (); add_pixmap_directory (deadbeef->get_system_dir (DDB_SYS_DIR_PIXMAP)); + covermanager_shared_init (); + #if GTK_CHECK_VERSION(3, 10, 0) && USE_GTK_APPLICATION gapp = deadbeef_app_new (); GValue val = G_VALUE_INIT; @@ -1796,6 +1794,10 @@ quit_gtk_cb (gpointer nothing) { gtkui_mainwin_free (); + covermanager_terminate (covermanager_shared ()); + // FIXME: can't do this, since artwork holds non-refcounted references to it + // covermanager_shared_free (); + supereq_plugin = NULL; trkproperties_modified = 0; trkproperties_destroy (); diff --git a/src/playlist.c b/src/playlist.c index c23266380e..b4afbd00aa 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -101,7 +101,9 @@ # error writing playlists in format <1.2 is not supported #endif -#define min(x, y) ((x) < (y) ? (x) : (y)) +#ifndef min +# define min(x, y) ((x) < (y) ? (x) : (y)) +#endif static int _playlists_count = 0; static playlist_t *_playlists_head = NULL;