Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiling-J committed Oct 1, 2024
1 parent d04b4aa commit 22b7bf2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
11 changes: 3 additions & 8 deletions seqlock/seq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,19 @@ type Node[K comparable, V any] struct {
}

func (n *Node[K, V]) Value() V {
values := make([]V, 1)
for {
seq := n.lock.Load()
if seq&1 != 0 {
runtime.Gosched()
continue
}

var value V

if seq > 1 {
value = n.value
} else {
value = n.value
}
values[seq&0] = n.value

seq2 := n.lock.Load()
if seq == seq2 {
return value
return values[seq&0]
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions seqlock/seqbench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@ func o1(n *t) any {
}
}

var l atomic.Uint32

func o2(n *t) any {
values := make([]any, 1)
for {
seq := n.lock.Load()
if seq&1 != 0 {
runtime.Gosched()
continue
}
value := n.value
l.CompareAndSwap(0, 0)
values[seq&0] = n.value

if seq == n.lock.Load() {
return value
return values[seq&0]
}
}
}
Expand Down

0 comments on commit 22b7bf2

Please sign in to comment.