diff options
Diffstat (limited to 'absl/synchronization/mutex_benchmark.cc')
-rw-r--r-- | absl/synchronization/mutex_benchmark.cc | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/absl/synchronization/mutex_benchmark.cc b/absl/synchronization/mutex_benchmark.cc index c3f54764..06888dfe 100644 --- a/absl/synchronization/mutex_benchmark.cc +++ b/absl/synchronization/mutex_benchmark.cc @@ -19,6 +19,7 @@ #include "absl/base/config.h" #include "absl/base/internal/cycleclock.h" #include "absl/base/internal/spinlock.h" +#include "absl/base/no_destructor.h" #include "absl/synchronization/blocking_counter.h" #include "absl/synchronization/internal/thread_pool.h" #include "absl/synchronization/mutex.h" @@ -27,17 +28,17 @@ namespace { void BM_Mutex(benchmark::State& state) { - static absl::Mutex* mu = new absl::Mutex; + static absl::NoDestructor<absl::Mutex> mu; for (auto _ : state) { - absl::MutexLock lock(mu); + absl::MutexLock lock(mu.get()); } } BENCHMARK(BM_Mutex)->UseRealTime()->Threads(1)->ThreadPerCpu(); void BM_ReaderLock(benchmark::State& state) { - static absl::Mutex* mu = new absl::Mutex; + static absl::NoDestructor<absl::Mutex> mu; for (auto _ : state) { - absl::ReaderMutexLock lock(mu); + absl::ReaderMutexLock lock(mu.get()); } } BENCHMARK(BM_ReaderLock)->UseRealTime()->Threads(1)->ThreadPerCpu(); @@ -53,7 +54,7 @@ void BM_TryLock(benchmark::State& state) { BENCHMARK(BM_TryLock); void BM_ReaderTryLock(benchmark::State& state) { - static absl::Mutex* mu = new absl::Mutex; + static absl::NoDestructor<absl::Mutex> mu; for (auto _ : state) { if (mu->ReaderTryLock()) { mu->ReaderUnlock(); @@ -133,7 +134,7 @@ void BM_MutexEnqueue(benchmark::State& state) { std::atomic<int> blocked_threads{0}; std::atomic<bool> thread_has_mutex{false}; }; - static Shared* shared = new Shared; + static absl::NoDestructor<Shared> shared; // Set up 'blocked_threads' to count how many threads are currently blocked // in Abseil synchronization code. @@ -211,7 +212,7 @@ void BM_Contended(benchmark::State& state) { MutexType mu; int data = 0; }; - static auto* shared = new Shared; + static absl::NoDestructor<Shared> shared; int local = 0; for (auto _ : state) { // Here we model both local work outside of the critical section as well as |