github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/compiler/natives/src/sync/go113_pool.go (about) 1 // +build js 2 // +build go1.13 3 4 package sync 5 6 import "unsafe" 7 8 type Pool struct { 9 local unsafe.Pointer 10 localSize uintptr 11 12 victim unsafe.Pointer 13 victimSize uintptr 14 15 store []interface{} 16 New func() interface{} 17 } 18 19 func (p *Pool) Get() interface{} { 20 if len(p.store) == 0 { 21 if p.New != nil { 22 return p.New() 23 } 24 return nil 25 } 26 x := p.store[len(p.store)-1] 27 p.store = p.store[:len(p.store)-1] 28 return x 29 } 30 31 func (p *Pool) Put(x interface{}) { 32 if x == nil { 33 return 34 } 35 p.store = append(p.store, x) 36 } 37 38 func runtime_registerPoolCleanup(cleanup func()) { 39 }