From a0b464b90bc98bf949001132835a88fdd8fc895c Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut <134911583+absolutelightning@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:33:28 +0530 Subject: [PATCH] Trying avoid data race (#98) * Ref counting (#5) * Reference counting * reference counting with memdb tests passing * removed atomic add * fixes in watch * fix go mod * fix memdb tests * trying to avoid data race --- node_16.go | 4 ++-- node_256.go | 4 ++-- node_4.go | 4 ++-- node_48.go | 4 ++-- node_leaf.go | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/node_16.go b/node_16.go index 4201599..7c68e0f 100644 --- a/node_16.go +++ b/node_16.go @@ -232,7 +232,7 @@ func (n *Node16[T]) LowerBoundIterator() *LowerBoundIterator[T] { } func (n *Node16[T]) incrementLazyRefCount(inc int64) { - n.lazyRefCount += inc + atomic.AddInt64(&n.lazyRefCount, inc) } func (n *Node16[T]) processRefCount() { @@ -248,7 +248,7 @@ func (n *Node16[T]) processRefCount() { child.incrementLazyRefCount(n.lazyRefCount) } } - n.lazyRefCount = 0 + atomic.StoreInt64(&n.lazyRefCount, 0) } func (n *Node16[T]) getRefCount() int64 { diff --git a/node_256.go b/node_256.go index 08401be..6f14b9b 100644 --- a/node_256.go +++ b/node_256.go @@ -229,7 +229,7 @@ func (n *Node256[T]) LowerBoundIterator() *LowerBoundIterator[T] { } func (n *Node256[T]) incrementLazyRefCount(inc int64) { - n.lazyRefCount += inc + atomic.AddInt64(&n.lazyRefCount, inc) } func (n *Node256[T]) processRefCount() { @@ -245,7 +245,7 @@ func (n *Node256[T]) processRefCount() { child.incrementLazyRefCount(n.lazyRefCount) } } - n.lazyRefCount = 0 + atomic.StoreInt64(&n.lazyRefCount, 0) } func (n *Node256[T]) getRefCount() int64 { diff --git a/node_4.go b/node_4.go index a916c6f..6aa380f 100644 --- a/node_4.go +++ b/node_4.go @@ -232,7 +232,7 @@ func (n *Node4[T]) LowerBoundIterator() *LowerBoundIterator[T] { } func (n *Node4[T]) incrementLazyRefCount(inc int64) { - n.lazyRefCount += inc + atomic.AddInt64(&n.lazyRefCount, inc) } func (n *Node4[T]) processRefCount() { @@ -248,7 +248,7 @@ func (n *Node4[T]) processRefCount() { child.incrementLazyRefCount(n.lazyRefCount) } } - n.lazyRefCount = 0 + atomic.StoreInt64(&n.lazyRefCount, 0) } func (n *Node4[T]) getRefCount() int64 { diff --git a/node_48.go b/node_48.go index 7daeaba..17745f9 100644 --- a/node_48.go +++ b/node_48.go @@ -237,7 +237,7 @@ func (n *Node48[T]) LowerBoundIterator() *LowerBoundIterator[T] { } func (n *Node48[T]) incrementLazyRefCount(inc int64) { - n.lazyRefCount += inc + atomic.AddInt64(&n.lazyRefCount, inc) } func (n *Node48[T]) processRefCount() { @@ -253,7 +253,7 @@ func (n *Node48[T]) processRefCount() { child.incrementLazyRefCount(n.lazyRefCount) } } - n.lazyRefCount = 0 + atomic.StoreInt64(&n.lazyRefCount, 0) } func (n *Node48[T]) getRefCount() int64 { diff --git a/node_leaf.go b/node_leaf.go index fb2a9a7..7f37dfa 100644 --- a/node_leaf.go +++ b/node_leaf.go @@ -206,12 +206,12 @@ func (n *NodeLeaf[T]) LowerBoundIterator() *LowerBoundIterator[T] { } func (n *NodeLeaf[T]) incrementLazyRefCount(inc int64) { - n.lazyRefCount += inc + atomic.AddInt64(&n.lazyRefCount, inc) } func (n *NodeLeaf[T]) processRefCount() { n.refCount += n.lazyRefCount - n.lazyRefCount = 0 + atomic.StoreInt64(&n.lazyRefCount, 0) } func (n *NodeLeaf[T]) getRefCount() int64 {