store: fix potential race.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 19:16:09 +0200
1 files changed,
5 insertions(+),
3 deletions(-)
jump to
M
store.go
→
store.go
@@ -62,10 +62,12 @@ s.mu.Lock()
s.digitsById[id] = digits s.idByTime.PushBack(idByTimeValue{time.Seconds(), id}) s.numStored++ - s.mu.Unlock() - if s.numStored > s.collectNum { - go s.Collect() + if s.numStored <= s.collectNum { + s.mu.Unlock() + return } + s.mu.Unlock() + go s.Collect() } func (s *memoryStore) Get(id string, clear bool) (digits []byte) {