Merge lp:~chipaca/ubuntu-push/session-state-lock into lp:ubuntu-push/automatic

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 372
Merged at revision: 374
Proposed branch: lp:~chipaca/ubuntu-push/session-state-lock
Merge into: lp:ubuntu-push/automatic
Prerequisite: lp:~chipaca/ubuntu-push/client-session-iface
Diff against target: 50 lines (+10/-6)
1 file modified
client/session/session.go (+10/-6)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/session-state-lock
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+252611@code.launchpad.net

Commit message

Make session lock explicit.

To post a comment you must log in.
Revision history for this message
Samuele Pedroni (pedronis) wrote :

looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/session/session.go'
2--- client/session/session.go 2015-03-11 17:01:25 +0000
3+++ client/session/session.go 2015-03-11 17:01:25 +0000
4@@ -158,7 +158,8 @@
5 retrierLock sync.Mutex
6 cookie string
7 // status
8- stateP *uint32
9+ stateLock sync.RWMutex
10+ state ClientSessionState
11 // authorization
12 auth string
13 // autoredial knobs
14@@ -186,7 +187,6 @@
15 func NewSession(serverAddrSpec string, conf ClientSessionConfig,
16 deviceId string, seenStateFactory func() (seenstate.SeenState, error),
17 log logger.Logger) (*clientSession, error) {
18- state := uint32(Disconnected)
19 seenState, err := seenStateFactory()
20 if err != nil {
21 return nil, err
22@@ -207,7 +207,7 @@
23 Protocolator: protocol.NewProtocol0,
24 SeenState: seenState,
25 TLS: &tls.Config{},
26- stateP: &state,
27+ state: Disconnected,
28 timeSince: time.Since,
29 shouldDelayP: &shouldDelay,
30 redialDelay: redialDelay,
31@@ -238,12 +238,16 @@
32 }
33
34 func (sess *clientSession) State() ClientSessionState {
35- return ClientSessionState(atomic.LoadUint32(sess.stateP))
36+ sess.stateLock.RLock()
37+ defer sess.stateLock.RUnlock()
38+ return sess.state
39 }
40
41 func (sess *clientSession) setState(state ClientSessionState) {
42- sess.Log.Debugf("session.setState: %s -> %s", ClientSessionState(atomic.LoadUint32(sess.stateP)), state)
43- atomic.StoreUint32(sess.stateP, uint32(state))
44+ sess.stateLock.Lock()
45+ defer sess.stateLock.Unlock()
46+ sess.Log.Debugf("session.setState: %s -> %s", sess.state, state)
47+ sess.state = state
48 }
49
50 func (sess *clientSession) setConnection(conn net.Conn) {

Subscribers

People subscribed via source and target branches