aboutsummaryrefslogtreecommitdiff
path: root/absl/synchronization/mutex_benchmark.cc
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2023-12-26 21:22:51 -0800
committerCopybara-Service <copybara-worker@google.com>2023-12-26 21:23:47 -0800
commitf9228ec834edef9b623d4824dd006890c203adc3 (patch)
treec41a1f543553fb5c8416005bfdb55048b2902d10 /absl/synchronization/mutex_benchmark.cc
parentbd47468324e0db12aac9a57128d40fc23c233fb4 (diff)
downloadabseil-f9228ec834edef9b623d4824dd006890c203adc3.tar.gz
abseil-f9228ec834edef9b623d4824dd006890c203adc3.tar.bz2
abseil-f9228ec834edef9b623d4824dd006890c203adc3.zip
Migrate static objects to NoDestructor in tests, testing libraries and benchmarks.
PiperOrigin-RevId: 593918110 Change-Id: Ide100c69b10e28011af17c7f82bb10eea072cad4
Diffstat (limited to 'absl/synchronization/mutex_benchmark.cc')
-rw-r--r--absl/synchronization/mutex_benchmark.cc15
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