diff options
Diffstat (limited to 'absl/flags/flag.cc')
-rw-r--r-- | absl/flags/flag.cc | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/absl/flags/flag.cc b/absl/flags/flag.cc index 0858259b..f7a457bf 100644 --- a/absl/flags/flag.cc +++ b/absl/flags/flag.cc @@ -15,32 +15,26 @@ #include "absl/flags/flag.h" -#include <cstring> +#include "absl/base/config.h" +#include "absl/flags/internal/commandlineflag.h" +#include "absl/flags/internal/flag.h" namespace absl { -inline namespace lts_2019_08_08 { - -// We want to validate the type mismatch between type definition and -// declaration. The lock-free implementation does not allow us to do it, -// so in debug builds we always use the slower implementation, which always -// validates the type. -#ifndef NDEBUG -#define ABSL_FLAGS_ATOMIC_GET(T) \ - T GetFlag(const absl::Flag<T>& flag) { return flag.Get(); } -#else -#define ABSL_FLAGS_ATOMIC_GET(T) \ - T GetFlag(const absl::Flag<T>& flag) { \ - T result; \ - if (flag.AtomicGet(&result)) { \ - return result; \ - } \ - return flag.Get(); \ - } -#endif +ABSL_NAMESPACE_BEGIN + +// This global mutex protects on-demand construction of flag objects in MSVC +// builds. +#if defined(_MSC_VER) && !defined(__clang__) + +namespace flags_internal { -ABSL_FLAGS_INTERNAL_FOR_EACH_LOCK_FREE(ABSL_FLAGS_ATOMIC_GET) +ABSL_CONST_INIT static absl::Mutex construction_guard(absl::kConstInit); -#undef ABSL_FLAGS_ATOMIC_GET +absl::Mutex* GetGlobalConstructionGuard() { return &construction_guard; } + +} // namespace flags_internal + +#endif -} // inline namespace lts_2019_08_08 +ABSL_NAMESPACE_END } // namespace absl |