swarm/storage: Eliminate potential duplicate gc under lock

This commit is contained in:
lash 2018-10-12 13:55:47 +02:00
parent 2bfa37cdb3
commit 916a3e196e

View file

@ -314,10 +314,12 @@ func decodeData(addr Address, data []byte) (*chunk, error) {
func (s *LDBStore) collectGarbage() error { func (s *LDBStore) collectGarbage() error {
// prevent duplicate gc from starting when one is already running // prevent duplicate gc from starting when one is already running
if len(s.gc.runC) == 0 { select {
case <-s.gc.runC:
default:
return nil return nil
} }
<-s.gc.runC
s.lock.Lock() s.lock.Lock()
entryCnt := s.entryCnt entryCnt := s.entryCnt
s.lock.Unlock() s.lock.Unlock()