Fix stale pages on rebuilds in GetPage with short refs

Fixes #13004
This commit is contained in:
Bjørn Erik Pedersen 2024-11-03 10:41:34 +01:00
parent 1f23b4949c
commit 30d9aea860
5 changed files with 51 additions and 11 deletions

View file

@ -36,7 +36,7 @@ type Init struct {
prev *Init
children []*Init
init onceMore
init OnceMore
out any
err error
f func(context.Context) (any, error)

View file

@ -18,19 +18,19 @@ import (
"sync/atomic"
)
// onceMore is similar to sync.Once.
// OnceMore is similar to sync.Once.
//
// Additional features are:
// * it can be reset, so the action can be repeated if needed
// * it has methods to check if it's done or in progress
type onceMore struct {
type OnceMore struct {
mu sync.Mutex
lock uint32
done uint32
}
func (t *onceMore) Do(f func()) {
func (t *OnceMore) Do(f func()) {
if atomic.LoadUint32(&t.done) == 1 {
return
}
@ -53,15 +53,15 @@ func (t *onceMore) Do(f func()) {
f()
}
func (t *onceMore) InProgress() bool {
func (t *OnceMore) InProgress() bool {
return atomic.LoadUint32(&t.lock) == 1
}
func (t *onceMore) Done() bool {
func (t *OnceMore) Done() bool {
return atomic.LoadUint32(&t.done) == 1
}
func (t *onceMore) ResetWithLock() *sync.Mutex {
func (t *OnceMore) ResetWithLock() *sync.Mutex {
t.mu.Lock()
defer atomic.StoreUint32(&t.done, 0)
return &t.mu