diff options
author | Max Kellermann <max@musicpd.org> | 2019-02-05 21:40:07 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-02-05 21:40:07 +0100 |
commit | c9ba4f3f9ca99742e25503be15963a96c0a9e356 (patch) | |
tree | 584bbd83638161b2eff1d23690fd8875c3fd6500 | |
parent | c0e9246a662044906e13125e0aae97662d59ef7c (diff) |
archive/List: add RAII class
-rw-r--r-- | src/Main.cxx | 6 | ||||
-rw-r--r-- | src/archive/ArchiveList.hxx | 11 | ||||
-rw-r--r-- | test/dump_text_file.cxx | 10 | ||||
-rw-r--r-- | test/run_input.cxx | 10 | ||||
-rw-r--r-- | test/visit_archive.cxx | 10 |
5 files changed, 25 insertions, 22 deletions
diff --git a/src/Main.cxx b/src/Main.cxx index 084d1ad4f..d86da37aa 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -529,7 +529,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) initPermissions(raw_config); spl_global_init(raw_config); #ifdef ENABLE_ARCHIVE - archive_plugin_init_all(); + const ScopeArchivePluginsInit archive_plugins_init; #endif pcm_convert_global_init(raw_config); @@ -671,9 +671,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) instance->FinishShutdownPartitions(); command_finish(); decoder_plugin_deinit_all(); -#ifdef ENABLE_ARCHIVE - archive_plugin_deinit_all(); -#endif + instance->rtio_thread.Stop(); instance->io_thread.Stop(); diff --git a/src/archive/ArchiveList.hxx b/src/archive/ArchiveList.hxx index ea0c5d09e..224ac08f3 100644 --- a/src/archive/ArchiveList.hxx +++ b/src/archive/ArchiveList.hxx @@ -46,4 +46,15 @@ archive_plugin_init_all(); void archive_plugin_deinit_all() noexcept; +class ScopeArchivePluginsInit { +public: + ScopeArchivePluginsInit() { + archive_plugin_init_all(); + } + + ~ScopeArchivePluginsInit() noexcept { + archive_plugin_deinit_all(); + } +}; + #endif diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx index df2e99c96..18cdc7061 100644 --- a/test/dump_text_file.cxx +++ b/test/dump_text_file.cxx @@ -38,21 +38,19 @@ class GlobalInit { EventThread io_thread; +#ifdef ENABLE_ARCHIVE + const ScopeArchivePluginsInit archive_plugins_init; +#endif + public: GlobalInit() { io_thread.Start(); -#ifdef ENABLE_ARCHIVE - archive_plugin_init_all(); -#endif input_stream_global_init(ConfigData(), io_thread.GetEventLoop()); } ~GlobalInit() { input_stream_global_finish(); -#ifdef ENABLE_ARCHIVE - archive_plugin_deinit_all(); -#endif } }; diff --git a/test/run_input.cxx b/test/run_input.cxx index 8fdf6f81a..c58316ba5 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -106,6 +106,10 @@ class GlobalInit { ConfigData config; EventThread io_thread; +#ifdef ENABLE_ARCHIVE + const ScopeArchivePluginsInit archive_plugins_init; +#endif + public: GlobalInit(Path config_path, bool verbose) { SetLogThreshold(verbose ? LogLevel::DEBUG : LogLevel::INFO); @@ -117,18 +121,12 @@ public: io_thread.Start(); -#ifdef ENABLE_ARCHIVE - archive_plugin_init_all(); -#endif input_stream_global_init(config, io_thread.GetEventLoop()); } ~GlobalInit() { input_stream_global_finish(); -#ifdef ENABLE_ARCHIVE - archive_plugin_deinit_all(); -#endif } }; diff --git a/test/visit_archive.cxx b/test/visit_archive.cxx index 9c9a9c0c5..2507b0846 100644 --- a/test/visit_archive.cxx +++ b/test/visit_archive.cxx @@ -38,21 +38,19 @@ class GlobalInit { EventThread io_thread; +#ifdef ENABLE_ARCHIVE + const ScopeArchivePluginsInit archive_plugins_init; +#endif + public: GlobalInit() { io_thread.Start(); -#ifdef ENABLE_ARCHIVE - archive_plugin_init_all(); -#endif input_stream_global_init(ConfigData(), io_thread.GetEventLoop()); } ~GlobalInit() { input_stream_global_finish(); -#ifdef ENABLE_ARCHIVE - archive_plugin_deinit_all(); -#endif } }; |