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)

This commit is contained in:
shin- 2013-04-03 05:39:39 -07:00
parent 7b74b9cab5
commit d1767bbf67
3 changed files with 6 additions and 4 deletions

View file

@ -127,7 +127,6 @@ func (container *Container) FromDisk() error {
if err := json.Unmarshal(data, container); err != nil {
return err
}
container.State.resetLock()
return nil
}

View file

@ -117,6 +117,7 @@ func (runtime *Runtime) Load(id string) (*Container, error) {
if err := container.FromDisk(); err != nil {
return nil, err
}
container.State.initLock()
if container.Id != id {
return container, fmt.Errorf("Container %s is stored at %s", container.Id, id)
}

View file

@ -39,9 +39,11 @@ func (s *State) setStopped(exitCode int) {
s.broadcast()
}
func (s *State) resetLock() {
s.stateChangeLock = &sync.Mutex{}
s.stateChangeCond = sync.NewCond(s.stateChangeLock)
func (s *State) initLock() {
if s.stateChangeLock == nil {
s.stateChangeLock = &sync.Mutex{}
s.stateChangeCond = sync.NewCond(s.stateChangeLock)
}
}
func (s *State) broadcast() {