mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
upgrade lock usage
This commit is contained in:
parent
fd5078c779
commit
e2c50738f8
2 changed files with 10 additions and 11 deletions
|
|
@ -525,19 +525,20 @@ func (dl *diffLayer) StorageList(accountHash common.Hash) ([]common.Hash, bool)
|
|||
dl.lock.RUnlock()
|
||||
return list, destructed // the cached list can't be nil
|
||||
}
|
||||
storageMap := dl.storageData[accountHash]
|
||||
dl.lock.RUnlock()
|
||||
|
||||
// No old sorted account list exists, generate a new one
|
||||
dl.lock.Lock()
|
||||
defer dl.lock.Unlock()
|
||||
|
||||
storageMap := dl.storageData[accountHash]
|
||||
storageList := make([]common.Hash, 0, len(storageMap))
|
||||
for k := range storageMap {
|
||||
storageList = append(storageList, k)
|
||||
}
|
||||
slices.SortFunc(storageList, common.Hash.Cmp)
|
||||
|
||||
// No old sorted account list exists, generate a new one
|
||||
dl.lock.Lock()
|
||||
dl.storageList[accountHash] = storageList
|
||||
dl.memory += uint64(len(dl.storageList)*common.HashLength + common.HashLength)
|
||||
dl.lock.Unlock()
|
||||
|
||||
return storageList, destructed
|
||||
}
|
||||
|
|
|
|||
|
|
@ -818,10 +818,12 @@ func (t *Tree) Verify(root common.Hash) error {
|
|||
// The lock of snapTree is assumed to be held already.
|
||||
func (t *Tree) disklayer() *diskLayer {
|
||||
var snap snapshot
|
||||
t.lock.RLock()
|
||||
for _, s := range t.layers {
|
||||
snap = s
|
||||
break
|
||||
}
|
||||
t.lock.RUnlock()
|
||||
if snap == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -829,6 +831,8 @@ func (t *Tree) disklayer() *diskLayer {
|
|||
case *diskLayer:
|
||||
return layer
|
||||
case *diffLayer:
|
||||
layer.lock.RLock()
|
||||
defer layer.lock.RUnlock()
|
||||
return layer.origin
|
||||
default:
|
||||
panic(fmt.Sprintf("%T: undefined layer", snap))
|
||||
|
|
@ -848,9 +852,6 @@ func (t *Tree) diskRoot() common.Hash {
|
|||
// generating is an internal helper function which reports whether the snapshot
|
||||
// is still under the construction.
|
||||
func (t *Tree) generating() (bool, error) {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
layer := t.disklayer()
|
||||
if layer == nil {
|
||||
return false, errors.New("disk layer is missing")
|
||||
|
|
@ -862,9 +863,6 @@ func (t *Tree) generating() (bool, error) {
|
|||
|
||||
// DiskRoot is a external helper function to return the disk layer root.
|
||||
func (t *Tree) DiskRoot() common.Hash {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
return t.diskRoot()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue