| 1 |
// +build js |
| 2 |
|
| 3 |
package sync |
| 4 |
|
| 5 |
import "unsafe" |
| 6 |
|
| 7 |
type Pool struct { |
| 8 |
local unsafe.Pointer |
| 9 |
localSize uintptr |
| 10 |
|
| 11 |
store []interface{} |
| 12 |
New func() interface{} |
| 13 |
} |
| 14 |
|
| 15 |
func (p *Pool) Get() interface{} { |
| 16 |
if len(p.store) == 0 { |
| 17 |
if p.New != nil { |
| 18 |
return p.New() |
| 19 |
} |
| 20 |
return nil |
| 21 |
} |
| 22 |
x := p.store[len(p.store)-1] |
| 23 |
p.store = p.store[:len(p.store)-1] |
| 24 |
return x |
| 25 |
} |
| 26 |
|
| 27 |
func (p *Pool) Put(x interface{}) { |
| 28 |
if x == nil { |
| 29 |
return |
| 30 |
} |
| 31 |
p.store = append(p.store, x) |
| 32 |
} |
| 33 |
|
| 34 |
func runtime_registerPoolCleanup(cleanup func()) { |
| 35 |
} |