File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change 1
1
package sync
2
2
3
+ import "internal/task"
4
+
3
5
// Pool is a very simple implementation of sync.Pool.
4
6
type Pool struct {
7
+ lock task.PMutex
5
8
New func () interface {}
6
9
items []interface {}
7
10
}
8
11
9
12
// Get returns an item in the pool, or the value of calling Pool.New() if there are no items.
10
13
func (p * Pool ) Get () interface {} {
14
+ p .lock .Lock ()
11
15
if len (p .items ) > 0 {
12
16
x := p .items [len (p .items )- 1 ]
13
17
p .items = p .items [:len (p .items )- 1 ]
18
+ p .lock .Unlock ()
14
19
return x
15
20
}
21
+ p .lock .Unlock ()
16
22
if p .New == nil {
17
23
return nil
18
24
}
@@ -21,5 +27,7 @@ func (p *Pool) Get() interface{} {
21
27
22
28
// Put adds a value back into the pool.
23
29
func (p * Pool ) Put (x interface {}) {
30
+ p .lock .Lock ()
24
31
p .items = append (p .items , x )
32
+ p .lock .Unlock ()
25
33
}
You can’t perform that action at this time.
0 commit comments