summaryrefslogtreecommitdiff
path: root/absl/base/internal/spinlock_benchmark.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/base/internal/spinlock_benchmark.cc')
-rw-r--r--absl/base/internal/spinlock_benchmark.cc9
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());
}
}