From d1767bbf672355b9063099d641106dd4ea5303b3 Mon Sep 17 00:00:00 2001 From: shin- Date: Wed, 3 Apr 2013 05:39:39 -0700 Subject: [PATCH] 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) --- container.go | 1 - runtime.go | 1 + state.go | 8 +++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/container.go b/container.go index b89885a17e..8f993a35e1 100644 --- a/container.go +++ b/container.go @@ -127,7 +127,6 @@ func (container *Container) FromDisk() error { if err := json.Unmarshal(data, container); err != nil { return err } - container.State.resetLock() return nil } diff --git a/runtime.go b/runtime.go index 9f571cf45a..e096202c61 100644 --- a/runtime.go +++ b/runtime.go @@ -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) } diff --git a/state.go b/state.go index c7e89f2e65..bf325a3eac 100644 --- a/state.go +++ b/state.go @@ -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() {