libcontainerd/pausemonitor_unix.go
934328d8
 // +build !windows
 
9c4570a9
 package libcontainerd
 
69f00a13
 import (
 	"sync"
 )
 
9c4570a9
 // pauseMonitor is helper to get notifications from pause state changes.
 type pauseMonitor struct {
69f00a13
 	sync.Mutex
9c4570a9
 	waiters map[string][]chan struct{}
 }
 
 func (m *pauseMonitor) handle(t string) {
69f00a13
 	m.Lock()
 	defer m.Unlock()
9c4570a9
 	if m.waiters == nil {
 		return
 	}
 	q, ok := m.waiters[t]
 	if !ok {
 		return
 	}
 	if len(q) > 0 {
 		close(q[0])
 		m.waiters[t] = q[1:]
 	}
 }
 
 func (m *pauseMonitor) append(t string, waiter chan struct{}) {
69f00a13
 	m.Lock()
 	defer m.Unlock()
9c4570a9
 	if m.waiters == nil {
 		m.waiters = make(map[string][]chan struct{})
 	}
 	_, ok := m.waiters[t]
 	if !ok {
 		m.waiters[t] = make([]chan struct{}, 0)
 	}
 	m.waiters[t] = append(m.waiters[t], waiter)
 }