Fix collection (locking and getting next value).
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 15:53:45 +0200
1 files changed,
5 insertions(+),
3 deletions(-)
jump to
M
store.go
→
store.go
@@ -40,13 +40,12 @@
// saveCaptcha saves the captcha id and the corresponding digits. func (s *store) saveCaptcha(id string, digits []byte) { s.mu.Lock() - defer s.mu.Unlock() s.ids[id] = digits s.exp.PushBack(expValue{time.Seconds(), id}) s.numStored++ + s.mu.Unlock() if s.numStored > s.collectNum { go s.collect() - s.numStored = 0 } }@@ -79,14 +78,17 @@ func (s *store) collect() {
now := time.Seconds() s.mu.Lock() defer s.mu.Unlock() - for e := s.exp.Front(); e != nil; e = e.Next() { + s.numStored = 0 + for e := s.exp.Front(); e != nil; { ev, ok := e.Value.(expValue) if !ok { return } if ev.timestamp+s.expiration < now { s.ids[ev.id] = nil, false + next := e.Next() s.exp.Remove(e) + e = next } else { return }