From 00e42c2d5652e5a00f078273d2a8e569f3fe57cf Mon Sep 17 00:00:00 2001 From: xing Date: Sat, 25 Feb 2023 14:46:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dsafety.map=20flush=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- safety/safemap.go | 4 +++- safety/safemap_test.go | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/safety/safemap.go b/safety/safemap.go index cab85ab..06a54bf 100644 --- a/safety/safemap.go +++ b/safety/safemap.go @@ -320,7 +320,9 @@ func (e *entry[V]) delete(px unsafe.Pointer) (value V, ok bool) { func (m *Map[K, V]) Flush() { m.mu.Lock() - m.missLocked() + m.dirty = nil + m.read.Store(readOnly[K, V]{m: m.dirty}) + m.misses = 0 m.mu.Unlock() } diff --git a/safety/safemap_test.go b/safety/safemap_test.go index aea66bc..6591018 100644 --- a/safety/safemap_test.go +++ b/safety/safemap_test.go @@ -32,10 +32,12 @@ func TestMap_Load(t *testing.T) { } p := taskPools.NewPools(10) var a0, a1 []int - for i := 0; i < 5000; i++ { - v := number.Rand(0, 1) + for i := 0; i < 15000; i++ { + v := number.Rand(0, 2) if 1 == v { a1 = append(a1, 1) + } else if 0 == v { + m.Flush() } else { a0 = append(a0, 0) }