core/state: use atomic.Bool (#26992)
This commit is contained in:
parent
79532a25b1
commit
fb8a3aaf1e
@ -103,7 +103,7 @@ type diffLayer struct {
|
|||||||
memory uint64 // Approximate guess as to how much memory we use
|
memory uint64 // Approximate guess as to how much memory we use
|
||||||
|
|
||||||
root common.Hash // Root hash to which this snapshot diff belongs to
|
root common.Hash // Root hash to which this snapshot diff belongs to
|
||||||
stale uint32 // Signals that the layer became stale (state progressed)
|
stale atomic.Bool // Signals that the layer became stale (state progressed)
|
||||||
|
|
||||||
// destructSet is a very special helper marker. If an account is marked as
|
// destructSet is a very special helper marker. If an account is marked as
|
||||||
// deleted, then it's recorded in this set. However it's allowed that an account
|
// deleted, then it's recorded in this set. However it's allowed that an account
|
||||||
@ -267,7 +267,7 @@ func (dl *diffLayer) Parent() snapshot {
|
|||||||
// Stale return whether this layer has become stale (was flattened across) or if
|
// Stale return whether this layer has become stale (was flattened across) or if
|
||||||
// it's still live.
|
// it's still live.
|
||||||
func (dl *diffLayer) Stale() bool {
|
func (dl *diffLayer) Stale() bool {
|
||||||
return atomic.LoadUint32(&dl.stale) != 0
|
return dl.stale.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Account directly retrieves the account associated with a particular hash in
|
// Account directly retrieves the account associated with a particular hash in
|
||||||
@ -449,7 +449,7 @@ func (dl *diffLayer) flatten() snapshot {
|
|||||||
|
|
||||||
// Before actually writing all our data to the parent, first ensure that the
|
// Before actually writing all our data to the parent, first ensure that the
|
||||||
// parent hasn't been 'corrupted' by someone else already flattening into it
|
// parent hasn't been 'corrupted' by someone else already flattening into it
|
||||||
if atomic.SwapUint32(&parent.stale, 1) != 0 {
|
if parent.stale.Swap(true) {
|
||||||
panic("parent diff layer is stale") // we've flattened into the same parent from two children, boo
|
panic("parent diff layer is stale") // we've flattened into the same parent from two children, boo
|
||||||
}
|
}
|
||||||
// Overwrite all the updated accounts blindly, merge the sorted list
|
// Overwrite all the updated accounts blindly, merge the sorted list
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
@ -272,7 +271,7 @@ func (t *Tree) Disable() {
|
|||||||
case *diffLayer:
|
case *diffLayer:
|
||||||
// If the layer is a simple diff, simply mark as stale
|
// If the layer is a simple diff, simply mark as stale
|
||||||
layer.lock.Lock()
|
layer.lock.Lock()
|
||||||
atomic.StoreUint32(&layer.stale, 1)
|
layer.stale.Store(true)
|
||||||
layer.lock.Unlock()
|
layer.lock.Unlock()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -726,7 +725,7 @@ func (t *Tree) Rebuild(root common.Hash) {
|
|||||||
case *diffLayer:
|
case *diffLayer:
|
||||||
// If the layer is a simple diff, simply mark as stale
|
// If the layer is a simple diff, simply mark as stale
|
||||||
layer.lock.Lock()
|
layer.lock.Lock()
|
||||||
atomic.StoreUint32(&layer.stale, 1)
|
layer.stale.Store(true)
|
||||||
layer.lock.Unlock()
|
layer.lock.Unlock()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user