Initialize the singleton-vault early in init()
authorYedidya Feldblum <yfeldblum@fb.com>
Fri, 14 Apr 2017 07:22:47 +0000 (00:22 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 14 Apr 2017 07:36:06 +0000 (00:36 -0700)
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

index 33c7bb03b38c16d7a94acb4992f319ffbcd5fb2c..d44a6d4416193ffcce7d80a21c21ba3562863e8c 100644 (file)
@@ -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