playlist/Registry: add RAII class

This commit is contained in:
Max Kellermann 2019-02-05 23:03:29 +01:00
parent a065c6e6b9
commit e9c45a9140
3 changed files with 13 additions and 6 deletions

View File

@ -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;
}

View File

@ -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.
*/

View File

@ -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());