Commit 481e06e6 by Eric Fiselier

Address review comments

parent 751e07d4
...@@ -235,7 +235,8 @@ enum TimeUnit { ...@@ -235,7 +235,8 @@ enum TimeUnit {
// benchmark to use. // benchmark to use.
class State { class State {
public: public:
State(size_t max_iters, bool has_x, int x, bool has_y, int y, int thread_i, int n_threads); State(size_t max_iters, bool has_x, int x, bool has_y, int y,
int thread_i, int n_threads);
// Returns true iff the benchmark should continue through another iteration. // Returns true iff the benchmark should continue through another iteration.
// NOTE: A benchmark may not return from the test until KeepRunning() has // NOTE: A benchmark may not return from the test until KeepRunning() has
......
...@@ -12,13 +12,13 @@ namespace internal { ...@@ -12,13 +12,13 @@ namespace internal {
typedef void(AbortHandlerT)(); typedef void(AbortHandlerT)();
inline AbortHandlerT*& get_abort_handler() { inline AbortHandlerT*& GetAbortHandler() {
static AbortHandlerT* handler = &std::abort; static AbortHandlerT* handler = &std::abort;
return handler; return handler;
} }
BENCHMARK_NORETURN inline void abort_handler() { BENCHMARK_NORETURN inline void CallAbortHandler() {
get_abort_handler()(); GetAbortHandler()();
std::abort(); // fallback to enforce noreturn std::abort(); // fallback to enforce noreturn
} }
...@@ -39,7 +39,7 @@ public: ...@@ -39,7 +39,7 @@ public:
BENCHMARK_NORETURN ~CheckHandler() noexcept(false) { BENCHMARK_NORETURN ~CheckHandler() noexcept(false) {
log_ << std::endl; log_ << std::endl;
abort_handler(); CallAbortHandler();
} }
CheckHandler & operator=(const CheckHandler&) = delete; CheckHandler & operator=(const CheckHandler&) = delete;
......
// Testing:
// State::PauseTiming()
// State::ResumeTiming()
// Test that CHECK's within these function diagnose when they are called
// outside of the KeepRunning() loop.
//
// NOTE: Users should NOT include or use src/check.h. This is only done in
// order to test library internals.
#include "benchmark/benchmark_api.h" #include "benchmark/benchmark_api.h"
#include "../src/check.h" #include "../src/check.h"
void test_handler() { void TestHandler() {
throw std::logic_error(""); throw std::logic_error("");
} }
...@@ -37,7 +45,7 @@ void BM_diagnostic_test(benchmark::State& state) { ...@@ -37,7 +45,7 @@ void BM_diagnostic_test(benchmark::State& state) {
BENCHMARK(BM_diagnostic_test); BENCHMARK(BM_diagnostic_test);
int main(int argc, char** argv) { int main(int argc, char** argv) {
benchmark::internal::get_abort_handler() = &test_handler; benchmark::internal::GetAbortHandler() = &TestHandler;
benchmark::Initialize(&argc, argv); benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks(); benchmark::RunSpecifiedBenchmarks();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment