1
0
mirror of https://github.com/docker/cli.git synced 2026-01-18 08:21:31 +03:00
Files
cli/components/engine/state.go
Andrea Luzzardi 358dcc8f2a go fmt
Upstream-commit: 73d7265429261029b7e6345821e9efe4ec37b10a
Component: engine
2013-01-22 17:30:37 -08:00

52 lines
796 B
Go

package docker
import (
"sync"
"time"
)
type State struct {
Running bool
Pid int
ExitCode int
StartedAt time.Time
stateChangeLock *sync.Mutex
stateChangeCond *sync.Cond
}
func newState() *State {
lock := new(sync.Mutex)
return &State{
stateChangeLock: lock,
stateChangeCond: sync.NewCond(lock),
}
}
func (s *State) setRunning(pid int) {
s.Running = true
s.ExitCode = 0
s.Pid = pid
s.StartedAt = time.Now()
s.broadcast()
}
func (s *State) setStopped(exitCode int) {
s.Running = false
s.Pid = 0
s.ExitCode = exitCode
s.broadcast()
}
func (s *State) broadcast() {
s.stateChangeLock.Lock()
s.stateChangeCond.Broadcast()
s.stateChangeLock.Unlock()
}
func (s *State) wait() {
s.stateChangeLock.Lock()
s.stateChangeCond.Wait()
s.stateChangeLock.Unlock()
}