protect counter race condition
This commit is contained in:
parent
dbab92f317
commit
d176afa7ec
1 changed files with 4 additions and 0 deletions
|
|
@ -321,8 +321,12 @@ func (fc *fakeCheckpoint) Get(streamName, shardID string) (string, error) {
|
||||||
// implementation of counter
|
// implementation of counter
|
||||||
type fakeCounter struct {
|
type fakeCounter struct {
|
||||||
counter int64
|
counter int64
|
||||||
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fc *fakeCounter) Add(streamName string, count int64) {
|
func (fc *fakeCounter) Add(streamName string, count int64) {
|
||||||
|
fc.mu.Lock()
|
||||||
|
defer fc.mu.Unlock()
|
||||||
|
|
||||||
fc.counter += count
|
fc.counter += count
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue