@ -258,24 +258,11 @@ func (t *Tree) Disable() {
for _ , layer := range t . layers {
for _ , layer := range t . layers {
switch layer := layer . ( type ) {
switch layer := layer . ( type ) {
case * diskLayer :
case * diskLayer :
// TODO this function will hang if it's called twice. Will
layer . lock . RLock ( )
// fix it in the following PRs.
generating := layer . genMarker != nil
layer . stopGeneration ( )
layer . lock . RUnlock ( )
layer . markStale ( )
if ! generating {
layer . Release ( )
// Generator is already aborted or finished
break
}
// If the base layer is generating, abort it
if layer . genAbort != nil {
abort := make ( chan * generatorStats )
layer . genAbort <- abort
<- abort
}
// Layer should be inactive now, mark it as stale
layer . lock . Lock ( )
layer . stale = true
layer . lock . Unlock ( )
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
@ -730,16 +717,11 @@ func (t *Tree) Rebuild(root common.Hash) {
for _ , layer := range t . layers {
for _ , layer := range t . layers {
switch layer := layer . ( type ) {
switch layer := layer . ( type ) {
case * diskLayer :
case * diskLayer :
// If the base layer is generating, abort it and save
// TODO this function will hang if it's called twice. Will
if layer . genAbort != nil {
// fix it in the following PRs.
abort := make ( chan * generatorStats )
layer . stopGeneration ( )
layer . genAbort <- abort
layer . markStale ( )
<- abort
layer . Release ( )
}
// Layer should be inactive now, mark it as stale
layer . lock . Lock ( )
layer . stale = true
layer . lock . Unlock ( )
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