Skip to content
This repository has been archived by the owner on Jul 22, 2018. It is now read-only.

Commit

Permalink
Merge pull request #25 from lrita/v2.0.0
Browse files Browse the repository at this point in the history
using sync.RWMutex instead of sync.Mutex in channelPool.
  • Loading branch information
fatih authored Jan 17, 2018
2 parents f83b9d9 + 5abcdf4 commit 830a0f4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// channelPool implements the Pool interface based on buffered channels.
type channelPool struct {
// storage for our net.Conn connections
mu sync.Mutex
mu sync.RWMutex
conns chan net.Conn

// net.Conn generator
Expand Down Expand Up @@ -51,10 +51,10 @@ func NewChannelPool(initialCap, maxCap int, factory Factory) (Pool, error) {
}

func (c *channelPool) getConnsAndFactory() (chan net.Conn, Factory) {
c.mu.Lock()
c.mu.RLock()
conns := c.conns
factory := c.factory
c.mu.Unlock()
c.mu.RUnlock()
return conns, factory
}

Expand Down Expand Up @@ -93,8 +93,8 @@ func (c *channelPool) put(conn net.Conn) error {
return errors.New("connection is nil. rejecting")
}

c.mu.Lock()
defer c.mu.Unlock()
c.mu.RLock()
defer c.mu.RUnlock()

if c.conns == nil {
// pool is closed, close passed connection
Expand Down

0 comments on commit 830a0f4

Please # to comment.