| 1 |
// Copyright 2012 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package sync |
| 6 |
|
| 7 |
// Export for testing. |
| 8 |
var Runtime_Semacquire = runtime_Semacquire |
| 9 |
var Runtime_Semrelease = runtime_Semrelease |
| 10 |
var Runtime_procPin = runtime_procPin |
| 11 |
var Runtime_procUnpin = runtime_procUnpin |
| 12 |
|
| 13 |
// PoolDequeue exports an interface for pollDequeue testing. |
| 14 |
type PoolDequeue interface { |
| 15 |
PushHead(val any) bool |
| 16 |
PopHead() (any, bool) |
| 17 |
PopTail() (any, bool) |
| 18 |
} |
| 19 |
|
| 20 |
func NewPoolDequeue(n int) PoolDequeue { |
| 21 |
d := &poolDequeue{ |
| 22 |
vals: make([]eface, n), |
| 23 |
} |
| 24 |
// For testing purposes, set the head and tail indexes close |
| 25 |
// to wrapping around. |
| 26 |
d.headTail.Store(d.pack(1<<dequeueBits-500, 1<<dequeueBits-500)) |
| 27 |
return d |
| 28 |
} |
| 29 |
|
| 30 |
func (d *poolDequeue) PushHead(val any) bool { |
| 31 |
return d.pushHead(val) |
| 32 |
} |
| 33 |
|
| 34 |
func (d *poolDequeue) PopHead() (any, bool) { |
| 35 |
return d.popHead() |
| 36 |
} |
| 37 |
|
| 38 |
func (d *poolDequeue) PopTail() (any, bool) { |
| 39 |
return d.popTail() |
| 40 |
} |
| 41 |
|
| 42 |
func NewPoolChain() PoolDequeue { |
| 43 |
return new(poolChain) |
| 44 |
} |
| 45 |
|
| 46 |
func (c *poolChain) PushHead(val any) bool { |
| 47 |
c.pushHead(val) |
| 48 |
return true |
| 49 |
} |
| 50 |
|
| 51 |
func (c *poolChain) PopHead() (any, bool) { |
| 52 |
return c.popHead() |
| 53 |
} |
| 54 |
|
| 55 |
func (c *poolChain) PopTail() (any, bool) { |
| 56 |
return c.popTail() |
| 57 |
} |