mirror of https://github.com/google/benchmark.git
Fix a bug in the destruction of BenchmarkFamilies.
This commit is contained in:
parent
35da167b9e
commit
10dc155372
|
@ -343,6 +343,14 @@ BenchmarkFamilies::~BenchmarkFamilies() {
|
||||||
|
|
||||||
int BenchmarkFamilies::AddBenchmark(Benchmark* family) {
|
int BenchmarkFamilies::AddBenchmark(Benchmark* family) {
|
||||||
mutex_lock l(&benchmark_mutex);
|
mutex_lock l(&benchmark_mutex);
|
||||||
|
// This loop attempts to reuse an entry that was previously removed to avoid
|
||||||
|
// unncessary growth of the vector.
|
||||||
|
for (int index = 0; index < families_.size(); ++index) {
|
||||||
|
if (families_[index] == nullptr) {
|
||||||
|
families_[index] = family;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
int index = families_.size();
|
int index = families_.size();
|
||||||
families_.push_back(family);
|
families_.push_back(family);
|
||||||
return index;
|
return index;
|
||||||
|
@ -351,11 +359,8 @@ int BenchmarkFamilies::AddBenchmark(Benchmark* family) {
|
||||||
void BenchmarkFamilies::RemoveBenchmark(int index) {
|
void BenchmarkFamilies::RemoveBenchmark(int index) {
|
||||||
mutex_lock l(&benchmark_mutex);
|
mutex_lock l(&benchmark_mutex);
|
||||||
families_[index] = NULL;
|
families_[index] = NULL;
|
||||||
|
// Don't shrink families_ here, we might be called by the destructor of
|
||||||
// Shrink the vector if convenient.
|
// BenchmarkFamilies which iterates over the vector.
|
||||||
while (!families_.empty() && families_.back() == NULL) {
|
|
||||||
families_.pop_back();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BenchmarkFamilies::FindBenchmarks(
|
void BenchmarkFamilies::FindBenchmarks(
|
||||||
|
|
Loading…
Reference in New Issue