diff options
author | Abseil Team <absl-team@google.com> | 2023-12-26 21:22:51 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-12-26 21:23:47 -0800 |
commit | f9228ec834edef9b623d4824dd006890c203adc3 (patch) | |
tree | c41a1f543553fb5c8416005bfdb55048b2902d10 /absl/base/internal | |
parent | bd47468324e0db12aac9a57128d40fc23c233fb4 (diff) |
Migrate static objects to NoDestructor in tests, testing libraries and benchmarks.
PiperOrigin-RevId: 593918110
Change-Id: Ide100c69b10e28011af17c7f82bb10eea072cad4
Diffstat (limited to 'absl/base/internal')
-rw-r--r-- | absl/base/internal/spinlock_benchmark.cc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/absl/base/internal/spinlock_benchmark.cc b/absl/base/internal/spinlock_benchmark.cc index 7135d3f5..1790d967 100644 --- a/absl/base/internal/spinlock_benchmark.cc +++ b/absl/base/internal/spinlock_benchmark.cc @@ -18,6 +18,7 @@ #include "absl/base/internal/raw_logging.h" #include "absl/base/internal/scheduling_mode.h" #include "absl/base/internal/spinlock.h" +#include "absl/base/no_destructor.h" #include "absl/synchronization/internal/create_thread_identity.h" #include "benchmark/benchmark.h" @@ -31,7 +32,8 @@ static void BM_TryLock(benchmark::State& state) { nullptr, "GetOrCreateCurrentThreadIdentity() failed"); - static auto* spinlock = new absl::base_internal::SpinLock(scheduling_mode); + static absl::NoDestructor<absl::base_internal::SpinLock> spinlock( + scheduling_mode); for (auto _ : state) { if (spinlock->TryLock()) spinlock->Unlock(); } @@ -45,9 +47,10 @@ static void BM_SpinLock(benchmark::State& state) { nullptr, "GetOrCreateCurrentThreadIdentity() failed"); - static auto* spinlock = new absl::base_internal::SpinLock(scheduling_mode); + static absl::NoDestructor<absl::base_internal::SpinLock> spinlock( + scheduling_mode); for (auto _ : state) { - absl::base_internal::SpinLockHolder holder(spinlock); + absl::base_internal::SpinLockHolder holder(spinlock.get()); } } |