mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
sync: support Pool under race detector
Fixes #7203. R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/53020044
This commit is contained in:
parent
1fa7029425
commit
ce8045f393
2 changed files with 15 additions and 0 deletions
|
|
@ -72,6 +72,12 @@ func init() {
|
||||||
|
|
||||||
// Put adds x to the pool.
|
// Put adds x to the pool.
|
||||||
func (p *Pool) Put(x interface{}) {
|
func (p *Pool) Put(x interface{}) {
|
||||||
|
if raceenabled {
|
||||||
|
// Under race detector the Pool degenerates into no-op.
|
||||||
|
// It's conforming, simple and does not introduce excessive
|
||||||
|
// happens-before edges between unrelated goroutines.
|
||||||
|
return
|
||||||
|
}
|
||||||
if x == nil {
|
if x == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -95,6 +101,12 @@ func (p *Pool) Put(x interface{}) {
|
||||||
// If Get would otherwise return nil and p.New is non-nil, Get returns
|
// If Get would otherwise return nil and p.New is non-nil, Get returns
|
||||||
// the result of calling p.New.
|
// the result of calling p.New.
|
||||||
func (p *Pool) Get() interface{} {
|
func (p *Pool) Get() interface{} {
|
||||||
|
if raceenabled {
|
||||||
|
if p.New != nil {
|
||||||
|
return p.New()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
l := p.pin()
|
l := p.pin()
|
||||||
t := l.tail
|
t := l.tail
|
||||||
if t > 0 {
|
if t > 0 {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Pool is no-op under race detector, so all these tests do not work.
|
||||||
|
// +build !race
|
||||||
|
|
||||||
package sync_test
|
package sync_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue