mirror of
https://github.com/google/benchmark.git
synced 2025-04-29 22:40:33 +08:00
Construct the base class State of a ThreadState like
a usual State object instead of copying it. This fixes a bug, which otherwise happens, if one thread has already finished the benchmark loop and merged its results to the parent state, while another one hasn't started yet.
This commit is contained in:
parent
96569c63f7
commit
82ad95f371
@ -984,6 +984,7 @@ class BENCHMARK_EXPORT State {
|
||||
internal::ThreadManager* const manager_;
|
||||
|
||||
friend class internal::BenchmarkInstance;
|
||||
friend class ThreadState;
|
||||
|
||||
protected:
|
||||
void MergeThreadStateToParent(State& parent) const;
|
||||
|
@ -329,15 +329,16 @@ void State::MergeThreadStateToParent(State& parent) const {
|
||||
parent.num_thread_states_++;
|
||||
}
|
||||
|
||||
ThreadState::ThreadState(State& s) : State(s), parent_(&s) {
|
||||
BM_CHECK(!started())
|
||||
<< "Don't create a ThreadState object after measurement has started";
|
||||
timer_ = new internal::ThreadTimer(*timer_);
|
||||
if (perf_counters_measurement_) {
|
||||
perf_counters_measurement_ = new internal::PerfCountersMeasurement(
|
||||
perf_counters_measurement_->names());
|
||||
}
|
||||
}
|
||||
ThreadState::ThreadState(State& s)
|
||||
: State(s.name(), s.max_iterations, s.range_, s.thread_index(), s.threads(),
|
||||
new internal::ThreadTimer(
|
||||
internal::ThreadTimer::CreateFromTimer(*s.timer_)),
|
||||
s.manager_,
|
||||
s.perf_counters_measurement_
|
||||
? new internal::PerfCountersMeasurement(
|
||||
s.perf_counters_measurement_->names())
|
||||
: 0),
|
||||
parent_(&s) {}
|
||||
|
||||
ThreadState::~ThreadState() {
|
||||
BM_CHECK(error_occurred() || iterations() >= max_iterations)
|
||||
|
@ -18,6 +18,9 @@ class ThreadTimer {
|
||||
static ThreadTimer CreateProcessCpuTime() {
|
||||
return ThreadTimer(/*measure_process_cpu_time_=*/true);
|
||||
}
|
||||
static ThreadTimer CreateFromTimer(const ThreadTimer& timer) {
|
||||
return ThreadTimer(timer.measure_process_cpu_time);
|
||||
}
|
||||
|
||||
// Called by each thread
|
||||
void StartTimer() {
|
||||
|
Loading…
Reference in New Issue
Block a user