Skip to content

Commit

Permalink
Use absl::NoDestructor for global FlagRegistry.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 582861689
Change-Id: Iac257539ab282e9bfdc6d90e86c8da0c0d57b9c9
  • Loading branch information
Abseil Team authored and copybara-github committed Nov 16, 2023
1 parent aa14601 commit 20f92b1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions absl/flags/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ cc_library(
":private_handle_accessor",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/base:no_destructor",
"//absl/container:flat_hash_map",
"//absl/strings",
"//absl/synchronization",
Expand Down
1 change: 1 addition & 0 deletions absl/flags/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ absl_cc_library(
absl::strings
absl::synchronization
absl::flat_hash_map
absl::no_destructor
)

# Internal-only target, do not depend on directly.
Expand Down
3 changes: 2 additions & 1 deletion absl/flags/reflection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <string>

#include "absl/base/config.h"
#include "absl/base/no_destructor.h"
#include "absl/base/thread_annotations.h"
#include "absl/container/flat_hash_map.h"
#include "absl/flags/commandlineflag.h"
Expand Down Expand Up @@ -169,7 +170,7 @@ void FlagRegistry::RegisterFlag(CommandLineFlag& flag, const char* filename) {
}

FlagRegistry& FlagRegistry::GlobalRegistry() {
static FlagRegistry* global_registry = new FlagRegistry;
static absl::NoDestructor<FlagRegistry> global_registry;
return *global_registry;
}

Expand Down

0 comments on commit 20f92b1

Please sign in to comment.