Skip to content

Commit

Permalink
Trying avoid data race (#98)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
absolutelightning committed Jun 21, 2024
1 parent 45c6d12 commit a0b464b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions node_16.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions node_256.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions node_4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions node_48.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions node_leaf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a0b464b

Please sign in to comment.