From b8f6d32a45c73116af5e6ae2126b59e8497821b0 Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 14 May 2015 17:42:57 +0200 Subject: [PATCH] use channels instread of abused :) mutex lock for signaling db write for memstore removeOldest --- bzz/dbstore.go | 8 ++++++-- bzz/dpa.go | 2 +- bzz/localstore.go | 2 +- bzz/memstore.go | 5 +++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/bzz/dbstore.go b/bzz/dbstore.go index 8ca2f427ef..36c52bc4d8 100644 --- a/bzz/dbstore.go +++ b/bzz/dbstore.go @@ -259,7 +259,9 @@ func (s *dbStore) Put(chunk *Chunk) { var index dpaDBIndex if s.tryAccessIdx(ikey, &index) { - chunk.dbStored.Unlock() + if chunk.dbStored != nil { + close(chunk.dbStored) + } return // already exists, only update access } @@ -288,7 +290,9 @@ func (s *dbStore) Put(chunk *Chunk) { batch.Put(ikey, idata) s.db.Write(batch) - chunk.dbStored.Unlock() + if chunk.dbStored != nil { + close(chunk.dbStored) + } } // try to find index; if found, update access cnt and return true diff --git a/bzz/dpa.go b/bzz/dpa.go index 3bd6813a1c..401585b087 100644 --- a/bzz/dpa.go +++ b/bzz/dpa.go @@ -60,7 +60,7 @@ type Chunk struct { C chan bool // to signal data delivery by the dpa req *requestStatus // wg *sync.WaitGroup - dbStored sync.Mutex + dbStored chan bool source *peer } diff --git a/bzz/localstore.go b/bzz/localstore.go index 243eceda8b..7f6a4eabd8 100644 --- a/bzz/localstore.go +++ b/bzz/localstore.go @@ -9,7 +9,7 @@ type localStore struct { // localStore is itself a chunk store , to stores a chunk only // its integrity is checked ? func (self *localStore) Put(chunk *Chunk) { - chunk.dbStored.Lock() + chunk.dbStored = make(chan bool) self.memStore.Put(chunk) if chunk.wg != nil { chunk.wg.Add(1) diff --git a/bzz/memstore.go b/bzz/memstore.go index 73786856cd..9cca945e37 100644 --- a/bzz/memstore.go +++ b/bzz/memstore.go @@ -314,8 +314,9 @@ func (s *memStore) removeOldest() { } - node.entry.dbStored.Lock() - node.entry.dbStored.Unlock() + if node.entry.dbStored != nil { + <-node.entry.dbStored + } if node.entry.SData != nil { node.entry = nil