mirror of
https://github.com/golang/go
synced 2024-11-08 05:46:12 -07:00
93c05627f9
TestPoolDequeue in long mode does a little more than 1<<21 pushes. This was originally because the head and tail indexes were 21 bits and the intent was to test wrap-around behavior. However, in the final version they were both 32 bits, so the test no longer tested wrap-around. It would take too long to reach 32-bit wrap around in a test, so instead we initialize the poolDequeue with indexes that are already nearly at their limit. This keeps the knowledge of the maximum index in one place, and lets us test wrap-around even in short mode. Change-Id: Ib9b8d85b6d9b5be235849c2b32e81c809e806579 Reviewed-on: https://go-review.googlesource.com/c/go/+/183979 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
// Copyright 2012 The Go Authors. All rights reserved.
|
|
// 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
|
|
var Runtime_procPin = runtime_procPin
|
|
var Runtime_procUnpin = runtime_procUnpin
|
|
|
|
// poolDequeue testing.
|
|
type PoolDequeue interface {
|
|
PushHead(val interface{}) bool
|
|
PopHead() (interface{}, bool)
|
|
PopTail() (interface{}, bool)
|
|
}
|
|
|
|
func NewPoolDequeue(n int) PoolDequeue {
|
|
d := &poolDequeue{
|
|
vals: make([]eface, n),
|
|
}
|
|
// 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
|
|
}
|
|
|
|
func (d *poolDequeue) PushHead(val interface{}) bool {
|
|
return d.pushHead(val)
|
|
}
|
|
|
|
func (d *poolDequeue) PopHead() (interface{}, bool) {
|
|
return d.popHead()
|
|
}
|
|
|
|
func (d *poolDequeue) PopTail() (interface{}, bool) {
|
|
return d.popTail()
|
|
}
|
|
|
|
func NewPoolChain() PoolDequeue {
|
|
return new(poolChain)
|
|
}
|
|
|
|
func (c *poolChain) PushHead(val interface{}) bool {
|
|
c.pushHead(val)
|
|
return true
|
|
}
|
|
|
|
func (c *poolChain) PopHead() (interface{}, bool) {
|
|
return c.popHead()
|
|
}
|
|
|
|
func (c *poolChain) PopTail() (interface{}, bool) {
|
|
return c.popTail()
|
|
}
|