Skip to content

Commit

Permalink
Merge pull request #390 from DennisDenuto/master
Browse files Browse the repository at this point in the history
Prevent data --race error when recording a benchmark value from multiple go routines
  • Loading branch information
luan committed Nov 29, 2017
2 parents 652e15c + c0c4881 commit 7a241e9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/leafnodes/benchmarker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func (b *benchmarker) Time(name string, body func(), info ...interface{}) (elaps
}

func (b *benchmarker) RecordValue(name string, value float64, info ...interface{}) {
measurement := b.getMeasurement(name, "Smallest", " Largest", " Average", "", 3, info...)
b.mu.Lock()
measurement := b.getMeasurement(name, "Smallest", " Largest", " Average", "", 3, info...)
defer b.mu.Unlock()
measurement.Results = append(measurement.Results, value)
}

func (b *benchmarker) RecordValueWithPrecision(name string, value float64, units string, precision int, info ...interface{}) {
measurement := b.getMeasurement(name, "Smallest", " Largest", " Average", units, precision, info...)
b.mu.Lock()
measurement := b.getMeasurement(name, "Smallest", " Largest", " Average", units, precision, info...)
defer b.mu.Unlock()
measurement.Results = append(measurement.Results, value)
}
Expand Down

0 comments on commit 7a241e9

Please sign in to comment.