Skip to content

Commit

Permalink
fix EvictionTest data race error
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar committed Jan 4, 2016
1 parent 0c5dc20 commit 842df2d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Go Commons Pool

[![Build Status](https://travis-ci.org/jolestar/go-commons-pool.svg?branch=master)](https://travis-ci.org/jolestar/go-commons-pool)
[![Circle CI](https://circleci.com/gh/jolestar/go-commons-pool.svg?style=svg)](https://circleci.com/gh/jolestar/go-commons-pool)
[![Coverage Status](https://coveralls.io/repos/jolestar/go-commons-pool/badge.svg?branch=master&service=github&_day=201603)](https://coveralls.io/github/jolestar/go-commons-pool?branch=master)
[![Coverage Status](https://coveralls.io/repos/jolestar/go-commons-pool/badge.svg?branch=master&service=github&_day=201604)](https://coveralls.io/github/jolestar/go-commons-pool?branch=master)
[![GoDoc](http://godoc.org/github.com/jolestar/go-commons-pool?status.svg)](http://godoc.org/github.com/jolestar/go-commons-pool)

The Go Commons Pool is a [Go](http://golang.org/) generic object pool, direct translate from [Apache Commons Pool](https://commons.apache.org/proper/commons-pool/).
Expand Down
8 changes: 6 additions & 2 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ func (this *PooledObject) markReturning() {
this.state = RETURNING
}

func (this *PooledObject) startEvictionTest() bool {
func (this *PooledObject) StartEvictionTest() bool {
this.lock.Lock()
defer this.lock.Unlock()
if this.state == IDLE {
this.state = EVICTION
return true
Expand All @@ -181,7 +183,9 @@ func (this *PooledObject) startEvictionTest() bool {
return false
}

func (this *PooledObject) endEvictionTest(idleQueue *collections.LinkedBlockDeque) bool {
func (this *PooledObject) EndEvictionTest(idleQueue *collections.LinkedBlockDeque) bool {
this.lock.Lock()
defer this.lock.Unlock()
if this.state == EVICTION {
this.state = IDLE
return true
Expand Down
4 changes: 2 additions & 2 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func (this *ObjectPool) evict() {
continue
}

if !underTest.startEvictionTest() {
if !underTest.StartEvictionTest() {
// Object was borrowed in another thread
// Don't count this as an eviction test so reduce i;
i--
Expand Down Expand Up @@ -625,7 +625,7 @@ func (this *ObjectPool) evict() {
}
}
}
if !underTest.endEvictionTest(this.idleObjects) {
if !underTest.EndEvictionTest(this.idleObjects) {
// TODO - May need to add code here once additional
// states are used
}
Expand Down

0 comments on commit 842df2d

Please sign in to comment.