Skip to content

Commit

Permalink
Merge pull request #20 from nkatsaros/master
Browse files Browse the repository at this point in the history
protect accumulator values with a mutex
  • Loading branch information
evanphx committed Jun 22, 2015
2 parents 480f29b + 8e90a44 commit 0d87eb4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import (
"fmt"
"sort"
"strings"
"sync"
"time"

"github.com/influxdb/influxdb/client"
)

type BatchPoints struct {
mu sync.Mutex

client.BatchPoints

Debug bool
Expand All @@ -20,6 +23,9 @@ type BatchPoints struct {
}

func (bp *BatchPoints) Add(measurement string, val interface{}, tags map[string]string) {
bp.mu.Lock()
defer bp.mu.Unlock()

measurement = bp.Prefix + measurement

if bp.Config != nil {
Expand Down Expand Up @@ -55,6 +61,9 @@ func (bp *BatchPoints) AddValuesWithTime(
tags map[string]string,
timestamp time.Time,
) {
bp.mu.Lock()
defer bp.mu.Unlock()

measurement = bp.Prefix + measurement

if bp.Config != nil {
Expand Down

0 comments on commit 0d87eb4

Please sign in to comment.