diff --git a/folly/init/Init.cpp b/folly/init/Init.cpp index 4e00c152ace..cee77dd736d 100644 --- a/folly/init/Init.cpp +++ b/folly/init/Init.cpp @@ -41,11 +41,7 @@ const unsigned long kAllFatalSignals = InitOptions::InitOptions() noexcept : fatal_signals(kAllFatalSignals) {} -void init(int* argc, char*** argv, bool removeFlags) { - InitOptions options; - options.removeFlags(removeFlags); - init(argc, argv, options); -} +namespace { #if FOLLY_USE_SYMBOLIZER // Newer versions of glog require the function passed to InstallFailureFunction @@ -65,7 +61,7 @@ wrapped_abort() { } #endif -void init(int* argc, char*** argv, InitOptions options) { +void initImpl(int* argc, char*** argv, InitOptions options) { #if !defined(_WIN32) // Install the handler now, to trap errors received during startup. // The callbacks, if any, can be installed later @@ -104,15 +100,26 @@ void init(int* argc, char*** argv, InitOptions options) { folly::enable_hazptr_thread_pool_executor(); } +} // namespace + Init::Init(int* argc, char*** argv, bool removeFlags) { - init(argc, argv, removeFlags); + initImpl(argc, argv, InitOptions{}.removeFlags(removeFlags)); } Init::Init(int* argc, char*** argv, InitOptions options) { - init(argc, argv, options); + initImpl(argc, argv, options); } Init::~Init() { SingletonVault::singleton()->destroyInstancesFinal(); } + +void init(int* argc, char*** argv, bool removeFlags) { + initImpl(argc, argv, InitOptions{}.removeFlags(removeFlags)); +} + +void init(int* argc, char*** argv, InitOptions options) { + initImpl(argc, argv, options); +} + } // namespace folly diff --git a/folly/init/Init.h b/folly/init/Init.h index dc445d68595..a8336d2d020 100644 --- a/folly/init/Init.h +++ b/folly/init/Init.h @@ -17,7 +17,7 @@ #pragma once #include -#include +#include namespace folly { class InitOptions { @@ -51,35 +51,26 @@ class InitOptions { } }; -/* - * Calls common init functions in the necessary order - * Among other things, this ensures that folly::Singletons are initialized - * correctly and installs signal handlers for a superior debugging experience. - * It also initializes gflags and glog. - * - * @param argc, argv arguments to your main - * @param removeFlags if true, will update argc,argv to remove recognized - * gflags passed on the command line - * @param options options - */ - -void init(int* argc, char*** argv, bool removeFlags = true); - -void init(int* argc, char*** argv, InitOptions options); - /* * An RAII object to be constructed at the beginning of main() and destructed * implicitly at the end of main(). * - * The constructor performs the same setup as folly::init(), including - * initializing singletons managed by folly::Singleton. + * The constructor calls common init functions in the necessary order + * Among other things, this ensures that folly::Singletons are initialized + * correctly and installs signal handlers for a superior debugging experience. + * It also initializes gflags and glog. * * The destructor destroys all singletons managed by folly::Singleton, yielding * better shutdown behavior when performed at the end of main(). In particular, * this guarantees that all singletons managed by folly::Singleton are destroyed * before all Meyers singletons are destroyed. + * + * @param argc, argv arguments to your main + * @param removeFlags if true, will update argc,argv to remove recognized + * gflags passed on the command line + * @param options options */ -class Init { +class FOLLY_NODISCARD Init { public: // Force ctor & dtor out of line for better stack traces even with LTO. FOLLY_NOINLINE Init(int* argc, char*** argv, bool removeFlags = true); @@ -94,4 +85,9 @@ class Init { Init& operator=(Init&&) = delete; }; +[[deprecated("Use the RAII version Init")]] void init( + int* argc, char*** argv, bool removeFlags = true); +[[deprecated("Use the RAII version Init")]] void init( + int* argc, char*** argv, InitOptions options); + } // namespace folly