From a411c5f39eae10019582d3c19375ee8816f2e4ce Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Fri, 14 Apr 2017 00:22:47 -0700 Subject: [PATCH] Initialize the singleton-vault early in init() Summary: Initialize the singleton-vault early in `init()` to avoid ordering problems with other parts of `init()`. Initialization is done by calling `SingletonVault::singleton()->registrationComplete()`. Do that before (almost) everything, in particular, before parsing args and initializing logging. Note that this just marks it okay for singletons to be instantiated, but does not by itself instantiate any singletons. However, this is useful if, in some way, parsing args or initializing logging should happen to use singletons. Reviewed By: andriigrynenko Differential Revision: D4889777 fbshipit-source-id: 6817db22d38a498cd20e361fc574a146029432ec --- folly/init/Init.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/folly/init/Init.cpp b/folly/init/Init.cpp index 33c7bb03..d44a6d44 100644 --- a/folly/init/Init.cpp +++ b/folly/init/Init.cpp @@ -36,6 +36,10 @@ void init(int* argc, char*** argv, bool removeFlags) { google::InstallFailureSignalHandler(); #endif + // Move from the registration phase to the "you can actually instantiate + // things now" phase. + folly::SingletonVault::singleton()->registrationComplete(); + gflags::ParseCommandLineFlags(argc, argv, removeFlags); auto programName = argc && argv && *argc > 0 ? (*argv)[0] : "unknown"; @@ -44,13 +48,7 @@ void init(int* argc, char*** argv, bool removeFlags) { #ifdef FOLLY_USE_SYMBOLIZER // Don't use glog's DumpStackTraceAndExit; rely on our signal handler. google::InstallFailureFunction(abort); -#endif - // Move from the registration phase to the "you can actually instantiate - // things now" phase. - folly::SingletonVault::singleton()->registrationComplete(); - -#ifdef FOLLY_USE_SYMBOLIZER // Actually install the callbacks into the handler. folly::symbolizer::installFatalSignalCallbacks(); #endif -- 2.34.1