Browse code

Moved resetLock() to the Load() method ; changed resetLock() to initLock() and changed behavior to not modify the lock if it was already set (not nil)

shin- authored on 2013/04/03 21:39:39
Showing 3 changed files
... ...
@@ -127,7 +127,6 @@ func (container *Container) FromDisk() error {
127 127
 	if err := json.Unmarshal(data, container); err != nil {
128 128
 		return err
129 129
 	}
130
-	container.State.resetLock()
131 130
 	return nil
132 131
 }
133 132
 
... ...
@@ -117,6 +117,7 @@ func (runtime *Runtime) Load(id string) (*Container, error) {
117 117
 	if err := container.FromDisk(); err != nil {
118 118
 		return nil, err
119 119
 	}
120
+	container.State.initLock()
120 121
 	if container.Id != id {
121 122
 		return container, fmt.Errorf("Container %s is stored at %s", container.Id, id)
122 123
 	}
... ...
@@ -39,9 +39,11 @@ func (s *State) setStopped(exitCode int) {
39 39
 	s.broadcast()
40 40
 }
41 41
 
42
-func (s *State) resetLock() {
43
-	s.stateChangeLock = &sync.Mutex{}
44
-	s.stateChangeCond = sync.NewCond(s.stateChangeLock)
42
+func (s *State) initLock() {
43
+	if s.stateChangeLock == nil {
44
+		s.stateChangeLock = &sync.Mutex{}
45
+		s.stateChangeCond = sync.NewCond(s.stateChangeLock)
46
+	}
45 47
 }
46 48
 
47 49
 func (s *State) broadcast() {