Use absl::NoDestructor an absl::Mutex instance in the flags

library to prevent some exit-time destructor warnings

This is the convention in the rest of Abseil.

PiperOrigin-RevId: 734551159
Change-Id: I4c8eb12ea8e2b7b42605d6b587dfef2235a29b7e
This commit is contained in:
Derek Mauro
2025-03-07 07:30:39 -08:00
committed by Copybara-Service
parent 4a2ba8cade
commit 70ba73e6b1

View File

@@ -76,9 +76,13 @@ ABSL_CONST_INIT bool fromenv_needs_processing
ABSL_CONST_INIT bool tryfromenv_needs_processing
ABSL_GUARDED_BY(ProcessingChecksMutex()) = false;
ABSL_CONST_INIT absl::Mutex specified_flags_guard(absl::kConstInit);
absl::Mutex* SpecifiedFlagsMutex() {
static absl::NoDestructor<absl::Mutex> mutex;
return mutex.get();
}
ABSL_CONST_INIT std::vector<const CommandLineFlag*>* specified_flags
ABSL_GUARDED_BY(specified_flags_guard) = nullptr;
ABSL_GUARDED_BY(SpecifiedFlagsMutex()) = nullptr;
// Suggesting at most kMaxHints flags in case of misspellings.
ABSL_CONST_INIT const size_t kMaxHints = 100;
@@ -640,7 +644,7 @@ void ReportUnrecognizedFlags(
// --------------------------------------------------------------------
bool WasPresentOnCommandLine(absl::string_view flag_name) {
absl::ReaderMutexLock l(&specified_flags_guard);
absl::ReaderMutexLock l(SpecifiedFlagsMutex());
ABSL_INTERNAL_CHECK(specified_flags != nullptr,
"ParseCommandLine is not invoked yet");
@@ -767,7 +771,7 @@ HelpMode ParseAbseilFlagsOnlyImpl(
}
positional_args.push_back(argv[0]);
absl::MutexLock l(&flags_internal::specified_flags_guard);
absl::MutexLock l(flags_internal::SpecifiedFlagsMutex());
if (specified_flags == nullptr) {
specified_flags = new std::vector<const CommandLineFlag*>;
} else {