unix/SignalHandlers: add RAII class

This commit is contained in:
Max Kellermann 2019-02-05 21:33:56 +01:00
parent 40bde1eac9
commit 096c23f27d
2 changed files with 12 additions and 4 deletions

View File

@ -564,7 +564,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
#ifndef ANDROID
setup_log_output();
SignalHandlersInit(instance->event_loop);
const ScopeSignalHandlersInit signal_handlers_init(instance->event_loop);
#endif
instance->io_thread.Start();
@ -676,9 +676,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
#endif
instance->rtio_thread.Stop();
instance->io_thread.Stop();
#ifndef ANDROID
SignalHandlersFinish();
#endif
return EXIT_SUCCESS;
}

View File

@ -28,4 +28,15 @@ SignalHandlersInit(EventLoop &loop);
void
SignalHandlersFinish() noexcept;
class ScopeSignalHandlersInit {
public:
ScopeSignalHandlersInit(EventLoop &loop) {
SignalHandlersInit(loop);
}
~ScopeSignalHandlersInit() noexcept {
SignalHandlersFinish();
}
};
#endif