Fix pthread benchmarks.
PauseTiming and ResumeTiming are thread-local, and unbalanced calls to
them leads to obviously bogus results like:
Benchmark Time CPU Iterations
-----------------------------------------------------------------
BM_pthread_exit_and_join 212600 ns 59981418 ns 12
BM_pthread_create_and_run 212997341 ns -1569132344 ns 1000
Bug: http://b/68170209
Test: ran bionic benchmarks
Change-Id: Ia88cd6af9ff524443850d834a96cf5dd9c7f3ed9
diff --git a/benchmarks/pthread_benchmark.cpp b/benchmarks/pthread_benchmark.cpp
index 7a967ef..1ad6345 100644
--- a/benchmarks/pthread_benchmark.cpp
+++ b/benchmarks/pthread_benchmark.cpp
@@ -137,9 +137,7 @@
}
BIONIC_BENCHMARK(BM_pthread_create);
-static void* RunThread(void* arg) {
- benchmark::State& state = *reinterpret_cast<benchmark::State*>(arg);
- state.PauseTiming();
+static void* RunThread(void*) {
return NULL;
}
@@ -148,22 +146,18 @@
pthread_t thread;
pthread_create(&thread, NULL, RunThread, &state);
pthread_join(thread, NULL);
- state.ResumeTiming();
}
}
BIONIC_BENCHMARK(BM_pthread_create_and_run);
-static void* ExitThread(void* arg) {
- benchmark::State& state = *reinterpret_cast<benchmark::State*>(arg);
- state.ResumeTiming();
+static void* ExitThread(void*) {
pthread_exit(NULL);
}
static void BM_pthread_exit_and_join(benchmark::State& state) {
while (state.KeepRunning()) {
- state.PauseTiming();
pthread_t thread;
- pthread_create(&thread, NULL, ExitThread, &state);
+ pthread_create(&thread, NULL, ExitThread, nullptr);
pthread_join(thread, NULL);
}
}