修复safety.map flush bug

This commit is contained in:
xing 2023-02-25 14:46:13 +08:00
parent e978e86304
commit 00e42c2d56
2 changed files with 7 additions and 3 deletions

View File

@ -320,7 +320,9 @@ func (e *entry[V]) delete(px unsafe.Pointer) (value V, ok bool) {
func (m *Map[K, V]) Flush() { func (m *Map[K, V]) Flush() {
m.mu.Lock() m.mu.Lock()
m.missLocked() m.dirty = nil
m.read.Store(readOnly[K, V]{m: m.dirty})
m.misses = 0
m.mu.Unlock() m.mu.Unlock()
} }

View File

@ -32,10 +32,12 @@ func TestMap_Load(t *testing.T) {
} }
p := taskPools.NewPools(10) p := taskPools.NewPools(10)
var a0, a1 []int var a0, a1 []int
for i := 0; i < 5000; i++ { for i := 0; i < 15000; i++ {
v := number.Rand(0, 1) v := number.Rand(0, 2)
if 1 == v { if 1 == v {
a1 = append(a1, 1) a1 = append(a1, 1)
} else if 0 == v {
m.Flush()
} else { } else {
a0 = append(a0, 0) a0 = append(a0, 0)
} }