github.com/ph/moby@v1.13.1/libcontainerd/pausemonitor_unix.go (about) 1 // +build !windows 2 3 package libcontainerd 4 5 import ( 6 "sync" 7 ) 8 9 // pauseMonitor is helper to get notifications from pause state changes. 10 type pauseMonitor struct { 11 sync.Mutex 12 waiters map[string][]chan struct{} 13 } 14 15 func (m *pauseMonitor) handle(t string) { 16 m.Lock() 17 defer m.Unlock() 18 if m.waiters == nil { 19 return 20 } 21 q, ok := m.waiters[t] 22 if !ok { 23 return 24 } 25 if len(q) > 0 { 26 close(q[0]) 27 m.waiters[t] = q[1:] 28 } 29 } 30 31 func (m *pauseMonitor) append(t string, waiter chan struct{}) { 32 m.Lock() 33 defer m.Unlock() 34 if m.waiters == nil { 35 m.waiters = make(map[string][]chan struct{}) 36 } 37 _, ok := m.waiters[t] 38 if !ok { 39 m.waiters[t] = make([]chan struct{}, 0) 40 } 41 m.waiters[t] = append(m.waiters[t], waiter) 42 }