Address review comments on previous change.
A different way to silence the build warnings...
Test: treehugger
Change-Id: I3fec02ceb0dc2ea22fe1769c948db6c20f458614
diff --git a/benchmarks/atomic_benchmark.cpp b/benchmarks/atomic_benchmark.cpp
index 487b71c..e3a6fb2 100644
--- a/benchmarks/atomic_benchmark.cpp
+++ b/benchmarks/atomic_benchmark.cpp
@@ -37,11 +37,9 @@
// We assume that the compiler is not smart enough to optimize away fences in a single-threaded
// program. If that changes, we'll need to add a second thread.
-// We're going to use `++` on this volatile in all the tests. This is
-// fine, because we're only using `volatile` in the "don't optimize this out"
-// sense, and don't care whether the increment is atomic or not.
-#pragma clang diagnostic ignored "-Wdeprecated-volatile"
+// We increment the counter this way to avoid -Wdeprecated-volatile warnings.
static volatile unsigned counter;
+#define INC_COUNTER() counter = counter + 1
std::atomic<int> test_loc(0);
@@ -51,7 +49,7 @@
void BM_atomic_empty(benchmark::State& state) {
while (state.KeepRunning()) {
- ++counter;
+ INC_COUNTER();
}
}
BIONIC_BENCHMARK(BM_atomic_empty);
@@ -60,7 +58,7 @@
unsigned result = 0;
while (state.KeepRunning()) {
result += test_loc.load(std::memory_order_relaxed);
- ++counter;
+ INC_COUNTER();
}
sink = result;
}
@@ -70,7 +68,7 @@
unsigned result = 0;
while (state.KeepRunning()) {
result += test_loc.load(std::memory_order_acquire);
- ++counter;
+ INC_COUNTER();
}
sink = result;
}
@@ -80,7 +78,7 @@
int i = counter;
while (state.KeepRunning()) {
test_loc.store(++i, std::memory_order_release);
- ++counter;
+ INC_COUNTER();
}
}
BIONIC_BENCHMARK(BM_atomic_store_release);
@@ -89,7 +87,7 @@
int i = counter;
while (state.KeepRunning()) {
test_loc.store(++i, std::memory_order_seq_cst);
- ++counter;
+ INC_COUNTER();
}
}
BIONIC_BENCHMARK(BM_atomic_store_seq_cst);
@@ -98,7 +96,7 @@
unsigned result = 0;
while (state.KeepRunning()) {
result += test_loc.fetch_add(1, std::memory_order_relaxed);
- ++counter;
+ INC_COUNTER();
}
sink = result;
}
@@ -108,7 +106,7 @@
unsigned result = 0;
while (state.KeepRunning()) {
result += test_loc.fetch_add(1, std::memory_order_seq_cst);
- ++counter;
+ INC_COUNTER();
}
sink = result;
}
@@ -122,7 +120,7 @@
while (state.KeepRunning()) {
result += test_loc.load(std::memory_order_relaxed);
std::atomic_thread_fence(std::memory_order_acquire);
- ++counter;
+ INC_COUNTER();
}
sink = result;
}
@@ -133,7 +131,7 @@
while (state.KeepRunning()) {
result += test_loc.load(std::memory_order_relaxed);
std::atomic_thread_fence(std::memory_order_seq_cst);
- ++counter;
+ INC_COUNTER();
}
sink = result;
}
@@ -146,7 +144,8 @@
while (state.KeepRunning()) {
{
std::lock_guard<std::mutex> _(mtx);
- result += ++counter;
+ INC_COUNTER();
+ result += counter;
}
}
sink = result;