mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
use channels instread of abused :) mutex lock for signaling db write for memstore removeOldest
This commit is contained in:
parent
8209e09790
commit
b8f6d32a45
4 changed files with 11 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue