Skip to content

Commit

Permalink
Remove accessors for lastZxid.
Browse files Browse the repository at this point in the history
It's only accessed in one goroutine at a time (read loop).
  • Loading branch information
samuel committed May 30, 2013
1 parent ce6fc8d commit d8db786
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type watchers struct {
}

type Conn struct {
lastZxid int64 // must be 64-bit aligned
lastZxid int64
sessionId int64
state State // must be 32-bit aligned
xid int32
Expand Down Expand Up @@ -145,14 +145,6 @@ func (c *Conn) setState(state State) {
}
}

func (c *Conn) zxid() int64 {
return atomic.LoadInt64(&c.lastZxid)
}

func (c *Conn) setZxid(zxid int64) {
atomic.StoreInt64(&c.lastZxid, zxid)
}

func (c *Conn) connect() {
startIndex := c.serverIndex
c.setState(StateConnecting)
Expand Down Expand Up @@ -275,7 +267,7 @@ func (c *Conn) sendSetWatches() {
}

req := &setWatchesRequest{
RelativeZxid: c.zxid(),
RelativeZxid: c.lastZxid,
DataWatches: make([]string, 0),
ExistWatches: make([]string, 0),
ChildWatches: make([]string, 0),
Expand Down Expand Up @@ -315,7 +307,7 @@ func (c *Conn) authenticate() error {

n, err := encodePacket(buf[4:], &connectRequest{
ProtocolVersion: protocolVersion,
LastZxidSeen: c.zxid(),
LastZxidSeen: c.lastZxid,
TimeOut: c.timeout,
SessionId: c.sessionId,
Passwd: c.passwd,
Expand Down Expand Up @@ -496,7 +488,7 @@ func (c *Conn) recvLoop(conn net.Conn) error {
}
c.watchersLock.Lock()
if wat := c.watchers[res.Path]; wat != nil {
zxid := c.zxid()
zxid := c.lastZxid
switch res.Type {
case EventNodeCreated:
wat.existWatchers = signalWatchers(wat.existWatchers, zxid, ev)
Expand All @@ -517,7 +509,7 @@ func (c *Conn) recvLoop(conn net.Conn) error {
log.Printf("Xid < 0 (%d) but not ping or watcher event", res.Xid)
} else {
if res.Zxid > 0 {
c.setZxid(res.Zxid)
c.lastZxid = res.Zxid
}

c.requestsLock.Lock()
Expand Down

0 comments on commit d8db786

Please sign in to comment.