From 3cf75074a3c2d3be2924f5b005771a9ea9b7789b Mon Sep 17 00:00:00 2001 From: Yiling-J Date: Tue, 1 Oct 2024 11:37:02 +0800 Subject: [PATCH] test --- .github/workflows/go.yaml | 6 +++--- seqlock/seq_test.go | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 5922b3c..af6caed 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -15,7 +15,7 @@ jobs: name: test strategy: matrix: - go: ["1.19.x", "1.22.x", "1.23.x"] + go: ["1.22.x"] runs-on: macos-latest steps: - name: Setup Go @@ -28,5 +28,5 @@ jobs: - name: Test run: go test ./... -run=TestNode_ -count=1 - - name: Bench - run: go test -run='^$' -bench BenchmarkNode_ ./... -timeout=0 + # - name: Bench + # run: go test -run='^$' -bench BenchmarkNode_ ./... -timeout=0 diff --git a/seqlock/seq_test.go b/seqlock/seq_test.go index a497aa4..b193812 100644 --- a/seqlock/seq_test.go +++ b/seqlock/seq_test.go @@ -15,6 +15,7 @@ package node import ( "runtime" + "sync" "sync/atomic" "testing" "time" @@ -26,11 +27,11 @@ type Node[K comparable, V any] struct { lock atomic.Uint32 } +var q sync.Mutex + func (n *Node[K, V]) Value() V { - var l atomic.Uint32 for { seq := n.lock.Load() - l.Load() if seq&1 != 0 { runtime.Gosched() continue @@ -38,7 +39,7 @@ func (n *Node[K, V]) Value() V { value := n.value - l.Add(0) + q.TryLock() if seq == n.lock.Load() { return value }