Make events chan local to supervisor

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2015-12-02 17:44:39 -08:00
parent 5eac8891ed
commit 3ea5dd79e0
2 changed files with 4 additions and 8 deletions

View file

@ -89,10 +89,9 @@ func daemon(stateDir string, concurrency, bufferSize int) error {
w := containerd.NewWorker(supervisor, wg) w := containerd.NewWorker(supervisor, wg)
go w.Start() go w.Start()
} }
events := make(chan *containerd.Event, bufferSize)
// start the signal handler in the background. // start the signal handler in the background.
go startSignalHandler(supervisor, bufferSize) go startSignalHandler(supervisor, bufferSize)
if err := supervisor.Start(events); err != nil { if err := supervisor.Start(); err != nil {
return err return err
} }
server := v1.NewServer(supervisor) server := v1.NewServer(supervisor)

View file

@ -31,6 +31,7 @@ func NewSupervisor(stateDir string, tasks chan *StartTask) (*Supervisor, error)
runtime: r, runtime: r,
journal: j, journal: j,
tasks: tasks, tasks: tasks,
events: make(chan *Event, 2048),
} }
// register default event handlers // register default event handlers
s.handlers = map[EventType]Handler{ s.handlers = map[EventType]Handler{
@ -87,16 +88,12 @@ func (s *Supervisor) NotifySubscribers(e *Event) {
// executing new containers. // executing new containers.
// //
// This event loop is the only thing that is allowed to modify state of containers and processes. // This event loop is the only thing that is allowed to modify state of containers and processes.
func (s *Supervisor) Start(events chan *Event) error { func (s *Supervisor) Start() error {
if events == nil {
return ErrEventChanNil
}
s.events = events
go func() { go func() {
// allocate an entire thread to this goroutine for the main event loop // allocate an entire thread to this goroutine for the main event loop
// so that nothing else is scheduled over the top of it. // so that nothing else is scheduled over the top of it.
goruntime.LockOSThread() goruntime.LockOSThread()
for e := range events { for e := range s.events {
EventsCounter.Inc(1) EventsCounter.Inc(1)
s.journal.write(e) s.journal.write(e)
h, ok := s.handlers[e.Type] h, ok := s.handlers[e.Type]