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 11package sync
22
3+ import "internal/task"
4+
35// Pool is a very simple implementation of sync.Pool.
46type Pool struct {
7+ lock task.PMutex
58 New func () interface {}
69 items []interface {}
710}
811
912// Get returns an item in the pool, or the value of calling Pool.New() if there are no items.
1013func (p * Pool ) Get () interface {} {
14+ p .lock .Lock ()
1115 if len (p .items ) > 0 {
1216 x := p .items [len (p .items )- 1 ]
1317 p .items = p .items [:len (p .items )- 1 ]
18+ p .lock .Unlock ()
1419 return x
1520 }
21+ p .lock .Unlock ()
1622 if p .New == nil {
1723 return nil
1824 }
@@ -21,5 +27,7 @@ func (p *Pool) Get() interface{} {
2127
2228// Put adds a value back into the pool.
2329func (p * Pool ) Put (x interface {}) {
30+ p .lock .Lock ()
2431 p .items = append (p .items , x )
32+ p .lock .Unlock ()
2533}
You can’t perform that action at this time.
0 commit comments