-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathpool.go
64 lines (54 loc) · 1007 Bytes
/
pool.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Package transport provides long-lived http/tcp connections for
// intra-cluster communications (see README for details and usage example).
/*
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
*/
package transport
import (
"io"
"sync"
"github.com/NVIDIA/aistore/cmn/debug"
)
//////////////
// sendPool //
//////////////
var (
sendPool sync.Pool
sobj0 Obj
)
func AllocSend() (obj *Obj) {
if v := sendPool.Get(); v != nil {
obj = v.(*Obj)
} else {
obj = &Obj{}
}
return
}
func freeSend(obj *Obj) { // <== sendobj & stream_bundle
*obj = sobj0
sendPool.Put(obj)
}
//////////////
// recvPool //
//////////////
var (
recvPool sync.Pool
robj0 objReader
)
func allocRecv() (obj *objReader) {
if v := recvPool.Get(); v != nil {
obj = v.(*objReader)
} else {
obj = &objReader{}
}
return
}
func FreeRecv(object io.Reader) {
if object == nil {
return
}
obj, ok := object.(*objReader)
debug.Assert(ok && obj != nil)
*obj = robj0
recvPool.Put(obj)
}