lib/icu/Init: add class ScopeIcuInit

This commit is contained in:
Max Kellermann 2018-08-02 10:16:56 +02:00
parent b8f3de693f
commit 22192adbc8
2 changed files with 15 additions and 4 deletions

View File

@ -466,8 +466,7 @@ MainOrThrow(int argc, char *argv[])
#endif
#endif
IcuInit();
const ScopeIcuInit icu_init;
const ScopeNetInit net_init;
#ifdef ENABLE_DBUS
@ -720,8 +719,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
daemonize_finish();
#endif
IcuFinish();
return EXIT_SUCCESS;
}

View File

@ -37,4 +37,18 @@ static inline void IcuFinish() noexcept {}
#endif
class ScopeIcuInit {
public:
ScopeIcuInit() {
IcuInit();
}
~ScopeIcuInit() noexcept {
IcuFinish();
}
ScopeIcuInit(const ScopeIcuInit &) = delete;
ScopeIcuInit &operator=(const ScopeIcuInit &) = delete;
};
#endif