File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ package memory
2+
3+ import (
4+ "sync/atomic"
5+
6+ "github.com/apache/arrow-go/v18/arrow/internal/debug"
7+ )
8+
9+ type Refcount struct {
10+ count atomic.Int64
11+ Dependencies []* * Refcount
12+ Buffers []* * Buffer
13+ Additional func ()
14+ }
15+
16+ func (r * Refcount ) Retain () {
17+ r .count .Add (1 )
18+ }
19+
20+ func (r * Refcount ) Release () {
21+ new := r .count .Add (- 1 )
22+ if new == 0 {
23+ for _ , buffer := range r .Buffers {
24+ (* buffer ).Release ()
25+ * buffer = nil
26+ }
27+ for _ , dependency := range r .Dependencies {
28+ (* dependency ).Release ()
29+ * dependency = nil
30+ }
31+ r .Buffers = nil
32+ r .Dependencies = nil
33+ if r .Additional != nil {
34+ r .Additional ()
35+ }
36+ } else if new < 0 {
37+ // This branch can be optimized out when !debug
38+ // This avoids an unnecessary extra Load
39+ debug .Assert (false , "too many releases" )
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments