diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 485ca64..282164f 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -60,7 +60,7 @@ }, { "ImportPath": "github.com/siddontang/goredis", - "Rev": "41bbdaa8d2015389bfa495ee4e7ee4d150376751" + "Rev": "f711beb9ecead18cf638a898610aa2c24ccb6dc7" }, { "ImportPath": "github.com/siddontang/rdb", diff --git a/Godeps/_workspace/src/github.com/siddontang/goredis/client.go b/Godeps/_workspace/src/github.com/siddontang/goredis/client.go index f5ba26d..b9682a9 100644 --- a/Godeps/_workspace/src/github.com/siddontang/goredis/client.go +++ b/Godeps/_workspace/src/github.com/siddontang/goredis/client.go @@ -13,7 +13,7 @@ type PoolConn struct { } func (c *PoolConn) Close() { - if c.Conn.closed { + if c.Conn.isClosed() { return } diff --git a/Godeps/_workspace/src/github.com/siddontang/goredis/conn.go b/Godeps/_workspace/src/github.com/siddontang/goredis/conn.go index 864c472..1c84346 100644 --- a/Godeps/_workspace/src/github.com/siddontang/goredis/conn.go +++ b/Godeps/_workspace/src/github.com/siddontang/goredis/conn.go @@ -8,6 +8,7 @@ import ( "io" "net" "strconv" + "sync/atomic" "time" ) @@ -38,7 +39,7 @@ type Conn struct { totalReadSize sizeWriter totalWriteSize sizeWriter - closed bool + closed int32 } func Connect(addr string) (*Conn, error) { @@ -57,18 +58,23 @@ func ConnectWithSize(addr string, readSize int, writeSize int) (*Conn, error) { c.br = bufio.NewReaderSize(io.TeeReader(c.c, &c.totalReadSize), readSize) c.bw = bufio.NewWriterSize(io.MultiWriter(c.c, &c.totalWriteSize), writeSize) - c.closed = false + atomic.StoreInt32(&c.closed, 0) return c, nil } func (c *Conn) Close() { - if c.closed { + if atomic.LoadInt32(&c.closed) == 1 { return } c.c.Close() - c.closed = true + + atomic.StoreInt32(&c.closed, 1) +} + +func (c *Conn) isClosed() bool { + return atomic.LoadInt32(&c.closed) == 1 } func (c *Conn) GetTotalReadSize() int64 {