Break big lock into some tiny locks

Don't involve code waiting for blocking channel in locked critical
section because it has potential risk of hanging forever.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Upstream-commit: 1326f0cba5f933674e23769de1385d3b0841e758
Component: engine
This commit is contained in:
Zhang Wei
2015-12-17 11:20:30 +08:00
parent f88ae3fe07
commit 189c56a7c6
3 changed files with 30 additions and 4 deletions

View File

@ -179,6 +179,13 @@ func (s *State) getExitCode() int {
return res
}
// SetRunningLocking locks container and sets it to "running"
func (s *State) SetRunningLocking(pid int) {
s.Lock()
s.SetRunning(pid)
s.Unlock()
}
// SetRunning sets the state of the container to "running".
func (s *State) SetRunning(pid int) {
s.Error = ""
@ -192,7 +199,7 @@ func (s *State) SetRunning(pid int) {
s.waitChan = make(chan struct{})
}
// SetStoppedLocking locks the container state is sets it to "stopped".
// SetStoppedLocking locks the container state and sets it to "stopped".
func (s *State) SetStoppedLocking(exitStatus *execdriver.ExitStatus) {
s.Lock()
s.SetStopped(exitStatus)