diff options
author | Max Kellermann <max@musicpd.org> | 2019-02-05 23:03:29 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-02-05 23:03:29 +0100 |
commit | e9c45a9140a6f10ae1e59bb5f7a6a4dc158a77aa (patch) | |
tree | 9389eda5fc4d562d788813d676b51f4fc9b02371 | |
parent | a065c6e6b9655c2a87e42bd957d6a561d4a52f91 (diff) |
playlist/Registry: add RAII class
-rw-r--r-- | src/Main.cxx | 4 | ||||
-rw-r--r-- | src/playlist/PlaylistRegistry.hxx | 11 | ||||
-rw-r--r-- | test/dump_playlist.cxx | 4 |
3 files changed, 13 insertions, 6 deletions
diff --git a/src/Main.cxx b/src/Main.cxx index 86fc9b09a..e5046a7ad 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -550,7 +550,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) client_manager_init(raw_config); const ScopeInputPluginsInit input_plugins_init(raw_config, instance->io_thread.GetEventLoop()); - playlist_list_global_init(raw_config); + const ScopePlaylistPluginsInit playlist_plugins_init(raw_config); #ifdef ENABLE_DAEMON daemonize_commit(); @@ -654,8 +654,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) sticker_global_finish(); #endif - playlist_list_global_finish(); - return EXIT_SUCCESS; } diff --git a/src/playlist/PlaylistRegistry.hxx b/src/playlist/PlaylistRegistry.hxx index 210015d50..7cd6fb348 100644 --- a/src/playlist/PlaylistRegistry.hxx +++ b/src/playlist/PlaylistRegistry.hxx @@ -47,6 +47,17 @@ playlist_list_global_init(const ConfigData &config); void playlist_list_global_finish() noexcept; +class ScopePlaylistPluginsInit { +public: + explicit ScopePlaylistPluginsInit(const ConfigData &config) { + playlist_list_global_init(config); + } + + ~ScopePlaylistPluginsInit() noexcept { + playlist_list_global_finish(); + } +}; + /** * Opens a playlist by its URI. */ diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx index 111fbc47f..c4aea7de8 100644 --- a/test/dump_playlist.cxx +++ b/test/dump_playlist.cxx @@ -65,7 +65,7 @@ try { io_thread.Start(); const ScopeInputPluginsInit input_plugins_init(config, io_thread.GetEventLoop()); - playlist_list_global_init(config); + const ScopePlaylistPluginsInit playlist_plugins_init(config); const ScopeDecoderPluginsInit decoder_plugins_init(config); /* open the playlist */ @@ -116,8 +116,6 @@ try { playlist.reset(); is.reset(); - playlist_list_global_finish(); - return EXIT_SUCCESS; } catch (...) { PrintException(std::current_exception()); |