summaryrefslogtreecommitdiff
path: root/absl/synchronization
diff options
context:
space:
mode:
Diffstat (limited to 'absl/synchronization')
-rw-r--r--absl/synchronization/BUILD.bazel2
-rw-r--r--absl/synchronization/blocking_counter_benchmark.cc5
-rw-r--r--absl/synchronization/mutex_benchmark.cc15
3 files changed, 13 insertions, 9 deletions
diff --git a/absl/synchronization/BUILD.bazel b/absl/synchronization/BUILD.bazel
index 0550b61c..de06ebdd 100644
--- a/absl/synchronization/BUILD.bazel
+++ b/absl/synchronization/BUILD.bazel
@@ -191,6 +191,7 @@ cc_binary(
deps = [
":synchronization",
":thread_pool",
+ "//absl/base:no_destructor",
"@com_github_google_benchmark//:benchmark_main",
],
)
@@ -291,6 +292,7 @@ cc_library(
":thread_pool",
"//absl/base",
"//absl/base:config",
+ "//absl/base:no_destructor",
"@com_github_google_benchmark//:benchmark_main",
],
alwayslink = 1,
diff --git a/absl/synchronization/blocking_counter_benchmark.cc b/absl/synchronization/blocking_counter_benchmark.cc
index b504d1a5..ea2bf9f9 100644
--- a/absl/synchronization/blocking_counter_benchmark.cc
+++ b/absl/synchronization/blocking_counter_benchmark.cc
@@ -14,6 +14,7 @@
#include <limits>
+#include "absl/base/no_destructor.h"
#include "absl/synchronization/blocking_counter.h"
#include "absl/synchronization/internal/thread_pool.h"
#include "benchmark/benchmark.h"
@@ -39,8 +40,8 @@ BENCHMARK(BM_BlockingCounter_SingleThread)
->Arg(256);
void BM_BlockingCounter_DecrementCount(benchmark::State& state) {
- static absl::BlockingCounter* counter =
- new absl::BlockingCounter{std::numeric_limits<int>::max()};
+ static absl::NoDestructor<absl::BlockingCounter> counter(
+ std::numeric_limits<int>::max());
for (auto _ : state) {
counter->DecrementCount();
}
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