reorganize bisect function so we lock it properly
This commit is contained in:
parent
ac77edcace
commit
7d492948ce
2 changed files with 19 additions and 6 deletions
|
@ -37,11 +37,7 @@ func PrepareResolveResult(
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var txCounts []interface{}
|
height, createdHeight := db.TxCounts.TxCountsBisectRight(txNum, rootTxNum, BisectRight)
|
||||||
txCounts = db.TxCounts.GetSlice()
|
|
||||||
txCounts = txCounts[:db.TxCounts.Len()]
|
|
||||||
height := BisectRight(txCounts, txNum)
|
|
||||||
createdHeight := BisectRight(txCounts, rootTxNum)
|
|
||||||
lastTakeoverHeight := controllingClaim.Height
|
lastTakeoverHeight := controllingClaim.Height
|
||||||
|
|
||||||
expirationHeight := GetExpirationHeight(height)
|
expirationHeight := GetExpirationHeight(height)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package db_stack
|
package db_stack
|
||||||
|
|
||||||
import "sync"
|
import (
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
type SliceBackedStack struct {
|
type SliceBackedStack struct {
|
||||||
slice []interface{}
|
slice []interface{}
|
||||||
|
@ -77,3 +79,18 @@ func (s *SliceBackedStack) GetSlice() []interface{} {
|
||||||
// This is not thread safe so I won't bother with locking
|
// This is not thread safe so I won't bother with locking
|
||||||
return s.slice
|
return s.slice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is dangerous because it assumes underlying types
|
||||||
|
func (s *SliceBackedStack) TxCountsBisectRight(
|
||||||
|
txNum, rootTxNum uint32,
|
||||||
|
bisectFunc func([]interface{}, uint32) uint32,
|
||||||
|
) (uint32, uint32) {
|
||||||
|
s.mut.RLock()
|
||||||
|
defer s.mut.RUnlock()
|
||||||
|
|
||||||
|
txCounts := s.slice[:s.Len()]
|
||||||
|
height := bisectFunc(txCounts, txNum)
|
||||||
|
createdHeight := bisectFunc(txCounts, rootTxNum)
|
||||||
|
|
||||||
|
return height, createdHeight
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue