2016-07-22 18:15:38 +00:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
2012-03-02 20:01:37 +00:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package sync
|
|
|
|
|
|
|
|
// Export for testing.
|
|
|
|
var Runtime_Semacquire = runtime_Semacquire
|
|
|
|
var Runtime_Semrelease = runtime_Semrelease
|
2017-09-14 17:11:35 +00:00
|
|
|
var Runtime_procPin = runtime_procPin
|
|
|
|
var Runtime_procUnpin = runtime_procUnpin
|
2019-09-06 18:12:46 +00:00
|
|
|
|
|
|
|
// poolDequeue testing.
|
|
|
|
type PoolDequeue interface {
|
2022-02-11 14:53:56 -08:00
|
|
|
PushHead(val any) bool
|
|
|
|
PopHead() (any, bool)
|
|
|
|
PopTail() (any, bool)
|
2019-09-06 18:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewPoolDequeue(n int) PoolDequeue {
|
2019-09-12 23:22:53 +00:00
|
|
|
d := &poolDequeue{
|
2019-09-06 18:12:46 +00:00
|
|
|
vals: make([]eface, n),
|
|
|
|
}
|
2019-09-12 23:22:53 +00:00
|
|
|
// For testing purposes, set the head and tail indexes close
|
|
|
|
// to wrapping around.
|
|
|
|
d.headTail = d.pack(1<<dequeueBits-500, 1<<dequeueBits-500)
|
|
|
|
return d
|
2019-09-06 18:12:46 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 14:53:56 -08:00
|
|
|
func (d *poolDequeue) PushHead(val any) bool {
|
2019-09-06 18:12:46 +00:00
|
|
|
return d.pushHead(val)
|
|
|
|
}
|
|
|
|
|
2022-02-11 14:53:56 -08:00
|
|
|
func (d *poolDequeue) PopHead() (any, bool) {
|
2019-09-06 18:12:46 +00:00
|
|
|
return d.popHead()
|
|
|
|
}
|
|
|
|
|
2022-02-11 14:53:56 -08:00
|
|
|
func (d *poolDequeue) PopTail() (any, bool) {
|
2019-09-06 18:12:46 +00:00
|
|
|
return d.popTail()
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPoolChain() PoolDequeue {
|
|
|
|
return new(poolChain)
|
|
|
|
}
|
|
|
|
|
2022-02-11 14:53:56 -08:00
|
|
|
func (c *poolChain) PushHead(val any) bool {
|
2019-09-06 18:12:46 +00:00
|
|
|
c.pushHead(val)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-02-11 14:53:56 -08:00
|
|
|
func (c *poolChain) PopHead() (any, bool) {
|
2019-09-06 18:12:46 +00:00
|
|
|
return c.popHead()
|
|
|
|
}
|
|
|
|
|
2022-02-11 14:53:56 -08:00
|
|
|
func (c *poolChain) PopTail() (any, bool) {
|
2019-09-06 18:12:46 +00:00
|
|
|
return c.popTail()
|
|
|
|
}
|