Fix infinite loop if semaphore test is not run.
When using the --benchmark_filter option, all of the test objects
get created, but not all are run. Previously, if this test didn't run
it would get into an infinite loop waiting for the test to complete.
This change only waits for the test to complete if it was actually
executed.
Change-Id: I5151a0b4b3d5349b978e716ec4a02ebd8b4eae00
diff --git a/benchmarks/semaphore_benchmark.cpp b/benchmarks/semaphore_benchmark.cpp
index d260803..b932a2b3 100644
--- a/benchmarks/semaphore_benchmark.cpp
+++ b/benchmarks/semaphore_benchmark.cpp
@@ -96,22 +96,27 @@
sched_setscheduler(0, SCHED_IDLE, ¶m);
BM_semaphore_sem_post_running = 1;
+ setup = true;
}
~SemaphoreFixture() {
- sched_setscheduler(0, SCHED_OTHER, ¶m);
+ if (setup) {
+ // Only do this if the test was actually run.
+ sched_setscheduler(0, SCHED_OTHER, ¶m);
- if (BM_semaphore_sem_post_running > 0) {
- BM_semaphore_sem_post_running = 0;
+ if (BM_semaphore_sem_post_running > 0) {
+ BM_semaphore_sem_post_running = 0;
+ }
+ do {
+ sem_post(&semaphore);
+ sched_yield();
+ } while (BM_semaphore_sem_post_running != -1);
}
- do {
- sem_post(&semaphore);
- sched_yield();
- } while (BM_semaphore_sem_post_running != -1);
}
sem_t semaphore;
sched_param param;
+ bool setup = false;
};
BENCHMARK_F(SemaphoreFixture, semaphore_sem_post)(benchmark::State& state) {