Init.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2016-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <folly/CPortability.h>
  18. /*
  19. * Calls common init functions in the necessary order
  20. * Among other things, this ensures that folly::Singletons are initialized
  21. * correctly and installs signal handlers for a superior debugging experience.
  22. * It also initializes gflags and glog.
  23. *
  24. * @param argc, argv arguments to your main
  25. * @param removeFlags if true, will update argc,argv to remove recognized
  26. * gflags passed on the command line
  27. */
  28. namespace folly {
  29. void init(int* argc, char*** argv, bool removeFlags = true);
  30. /*
  31. * An RAII object to be constructed at the beginning of main() and destructed
  32. * implicitly at the end of main().
  33. *
  34. * The constructor performs the same setup as folly::init(), including
  35. * initializing singletons managed by folly::Singleton.
  36. *
  37. * The destructor destroys all singletons managed by folly::Singleton, yielding
  38. * better shutdown behavior when performed at the end of main(). In particular,
  39. * this guarantees that all singletons managed by folly::Singleton are destroyed
  40. * before all Meyers singletons are destroyed.
  41. */
  42. class Init {
  43. public:
  44. // Force ctor & dtor out of line for better stack traces even with LTO.
  45. FOLLY_NOINLINE Init(int* argc, char*** argv, bool removeFlags = true);
  46. FOLLY_NOINLINE ~Init();
  47. };
  48. } // namespace folly