summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2023-11-15 17:52:29 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-11-15 17:53:34 -0800
commit20f92b10d5ae1dc03592b4b6caafec7b0e161252 (patch)
tree05a8dd00057421cad8f53b7307da41a29b784bd5
parentaa146013a1d8c2d9f567ec23f12927f5d838780f (diff)
Use absl::NoDestructor for global FlagRegistry.
PiperOrigin-RevId: 582861689 Change-Id: Iac257539ab282e9bfdc6d90e86c8da0c0d57b9c9
-rw-r--r--absl/flags/BUILD.bazel1
-rw-r--r--absl/flags/CMakeLists.txt1
-rw-r--r--absl/flags/reflection.cc3
3 files changed, 4 insertions, 1 deletions
diff --git a/absl/flags/BUILD.bazel b/absl/flags/BUILD.bazel
index f51fdf75..170d1ba8 100644
--- a/absl/flags/BUILD.bazel
+++ b/absl/flags/BUILD.bazel
@@ -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",
diff --git a/absl/flags/CMakeLists.txt b/absl/flags/CMakeLists.txt
index a535b55e..ddf2d4e7 100644
--- a/absl/flags/CMakeLists.txt
+++ b/absl/flags/CMakeLists.txt
@@ -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.
diff --git a/absl/flags/reflection.cc b/absl/flags/reflection.cc
index dbce4032..841921a9 100644
--- a/absl/flags/reflection.cc
+++ b/absl/flags/reflection.cc
@@ -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"
@@ -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;
}