Browse Source

store: fix potential race.

Dmitry Chestnykh 14 years ago
parent
commit
885d67a665
1 changed files with 5 additions and 3 deletions
  1. 5 3
      store.go

+ 5 - 3
store.go

@@ -62,10 +62,12 @@ func (s *memoryStore) Set(id string, digits []byte) {
 	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) {