Skip to content

Commit

Permalink
covermanager: threadsafe shared instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy-Yakovenko committed Nov 18, 2023
1 parent 10b8f9f commit 2042a2a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
9 changes: 5 additions & 4 deletions plugins/gtkui/covermanager/covermanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions plugins/gtkui/covermanager/covermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions plugins/gtkui/gtkui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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 ();
Expand Down
4 changes: 3 additions & 1 deletion src/playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2042a2a

Please sign in to comment.