From 51ee802e0923995ef6ba8d88783e4f484e260c14 Mon Sep 17 00:00:00 2001 From: Yiling-J Date: Tue, 1 Oct 2024 11:50:32 +0800 Subject: [PATCH] test --- seqlock/seq_test.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/seqlock/seq_test.go b/seqlock/seq_test.go index 0ac2055..839aedb 100644 --- a/seqlock/seq_test.go +++ b/seqlock/seq_test.go @@ -15,7 +15,6 @@ package node import ( "runtime" - "sync" "sync/atomic" "testing" "time" @@ -27,24 +26,19 @@ type Node[K comparable, V any] struct { lock atomic.Uint32 } -var q sync.Mutex +var l atomic.Uint32 func (n *Node[K, V]) Value() V { for { seq := n.lock.Load() - q.TryLock() if seq&1 != 0 { runtime.Gosched() continue } - t := q.TryLock() value := n.value - if t { - q.Unlock() - } - q.TryLock() + l.CompareAndSwap(0, 0) if seq == n.lock.Load() { return value }