Commit c9ba4f3f authored by Max Kellermann's avatar Max Kellermann

archive/List: add RAII class

parent c0e9246a
...@@ -529,7 +529,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) ...@@ -529,7 +529,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
initPermissions(raw_config); initPermissions(raw_config);
spl_global_init(raw_config); spl_global_init(raw_config);
#ifdef ENABLE_ARCHIVE #ifdef ENABLE_ARCHIVE
archive_plugin_init_all(); const ScopeArchivePluginsInit archive_plugins_init;
#endif #endif
pcm_convert_global_init(raw_config); pcm_convert_global_init(raw_config);
...@@ -671,9 +671,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) ...@@ -671,9 +671,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
instance->FinishShutdownPartitions(); instance->FinishShutdownPartitions();
command_finish(); command_finish();
decoder_plugin_deinit_all(); decoder_plugin_deinit_all();
#ifdef ENABLE_ARCHIVE
archive_plugin_deinit_all();
#endif
instance->rtio_thread.Stop(); instance->rtio_thread.Stop();
instance->io_thread.Stop(); instance->io_thread.Stop();
......
...@@ -46,4 +46,15 @@ archive_plugin_init_all(); ...@@ -46,4 +46,15 @@ archive_plugin_init_all();
void void
archive_plugin_deinit_all() noexcept; archive_plugin_deinit_all() noexcept;
class ScopeArchivePluginsInit {
public:
ScopeArchivePluginsInit() {
archive_plugin_init_all();
}
~ScopeArchivePluginsInit() noexcept {
archive_plugin_deinit_all();
}
};
#endif #endif
...@@ -38,21 +38,19 @@ ...@@ -38,21 +38,19 @@
class GlobalInit { class GlobalInit {
EventThread io_thread; EventThread io_thread;
#ifdef ENABLE_ARCHIVE
const ScopeArchivePluginsInit archive_plugins_init;
#endif
public: public:
GlobalInit() { GlobalInit() {
io_thread.Start(); io_thread.Start();
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all();
#endif
input_stream_global_init(ConfigData(), input_stream_global_init(ConfigData(),
io_thread.GetEventLoop()); io_thread.GetEventLoop());
} }
~GlobalInit() { ~GlobalInit() {
input_stream_global_finish(); input_stream_global_finish();
#ifdef ENABLE_ARCHIVE
archive_plugin_deinit_all();
#endif
} }
}; };
......
...@@ -106,6 +106,10 @@ class GlobalInit { ...@@ -106,6 +106,10 @@ class GlobalInit {
ConfigData config; ConfigData config;
EventThread io_thread; EventThread io_thread;
#ifdef ENABLE_ARCHIVE
const ScopeArchivePluginsInit archive_plugins_init;
#endif
public: public:
GlobalInit(Path config_path, bool verbose) { GlobalInit(Path config_path, bool verbose) {
SetLogThreshold(verbose ? LogLevel::DEBUG : LogLevel::INFO); SetLogThreshold(verbose ? LogLevel::DEBUG : LogLevel::INFO);
...@@ -117,18 +121,12 @@ public: ...@@ -117,18 +121,12 @@ public:
io_thread.Start(); io_thread.Start();
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all();
#endif
input_stream_global_init(config, input_stream_global_init(config,
io_thread.GetEventLoop()); io_thread.GetEventLoop());
} }
~GlobalInit() { ~GlobalInit() {
input_stream_global_finish(); input_stream_global_finish();
#ifdef ENABLE_ARCHIVE
archive_plugin_deinit_all();
#endif
} }
}; };
......
...@@ -38,21 +38,19 @@ ...@@ -38,21 +38,19 @@
class GlobalInit { class GlobalInit {
EventThread io_thread; EventThread io_thread;
#ifdef ENABLE_ARCHIVE
const ScopeArchivePluginsInit archive_plugins_init;
#endif
public: public:
GlobalInit() { GlobalInit() {
io_thread.Start(); io_thread.Start();
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all();
#endif
input_stream_global_init(ConfigData(), input_stream_global_init(ConfigData(),
io_thread.GetEventLoop()); io_thread.GetEventLoop());
} }
~GlobalInit() { ~GlobalInit() {
input_stream_global_finish(); input_stream_global_finish();
#ifdef ENABLE_ARCHIVE
archive_plugin_deinit_all();
#endif
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment