diff --git a/absl/status/BUILD.bazel b/absl/status/BUILD.bazel index 2b83077d..d164252d 100644 --- a/absl/status/BUILD.bazel +++ b/absl/status/BUILD.bazel @@ -40,6 +40,7 @@ cc_library( ], copts = ABSL_DEFAULT_COPTS, deps = [ + "//absl/base:atomic_hook", "//absl/base:config", "//absl/base:core_headers", "//absl/base:raw_logging_internal", diff --git a/absl/status/CMakeLists.txt b/absl/status/CMakeLists.txt index f05cee5e..c041d695 100644 --- a/absl/status/CMakeLists.txt +++ b/absl/status/CMakeLists.txt @@ -25,6 +25,7 @@ absl_cc_library( COPTS ${ABSL_DEFAULT_COPTS} DEPS + absl::atomic_hook absl::config absl::core_headers absl::raw_logging_internal diff --git a/absl/status/status_payload_printer.cc b/absl/status/status_payload_printer.cc index ad96d76a..a47aea11 100644 --- a/absl/status/status_payload_printer.cc +++ b/absl/status/status_payload_printer.cc @@ -16,26 +16,21 @@ #include #include "absl/base/attributes.h" +#include "absl/base/internal/atomic_hook.h" namespace absl { ABSL_NAMESPACE_BEGIN namespace status_internal { -namespace { -// Tried constant initialized global variable but it doesn't work with Lexan -// (MSVC's `std::atomic` has trouble constant initializing). -std::atomic& GetStatusPayloadPrinterStorage() { - ABSL_CONST_INIT static std::atomic instance{nullptr}; - return instance; -} -} // namespace +ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES +static absl::base_internal::AtomicHook storage; void SetStatusPayloadPrinter(StatusPayloadPrinter printer) { - GetStatusPayloadPrinterStorage().store(printer, std::memory_order_relaxed); + storage.Store(printer); } StatusPayloadPrinter GetStatusPayloadPrinter() { - return GetStatusPayloadPrinterStorage().load(std::memory_order_relaxed); + return storage.Load(); } } // namespace status_internal