forked from nutsdb/nutsdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue.go
More file actions
47 lines (39 loc) · 663 Bytes
/
Copy pathvalue.go
File metadata and controls
47 lines (39 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package nutsdb
import (
"sync"
"sync/atomic"
)
type request struct {
tx *Tx
Wg sync.WaitGroup
Err error
ref int32
}
var requestPool = sync.Pool{
New: func() interface{} {
return new(request)
},
}
func (req *request) reset() {
req.tx = nil
req.Wg = sync.WaitGroup{}
req.Err = nil
atomic.StoreInt32(&req.ref, 0)
}
func (req *request) IncrRef() {
atomic.AddInt32(&req.ref, 1)
}
func (req *request) DecrRef() {
nRef := atomic.AddInt32(&req.ref, -1)
if nRef > 0 {
return
}
req.tx = nil
requestPool.Put(req)
}
func (req *request) Wait() error {
req.Wg.Wait()
err := req.Err
req.DecrRef() // DecrRef after writing to DB.
return err
}