pausemonitor_linux.go 606 B

12345678910111213141516171819202122232425262728293031
  1. package libcontainerd
  2. // pauseMonitor is helper to get notifications from pause state changes.
  3. type pauseMonitor struct {
  4. waiters map[string][]chan struct{}
  5. }
  6. func (m *pauseMonitor) handle(t string) {
  7. if m.waiters == nil {
  8. return
  9. }
  10. q, ok := m.waiters[t]
  11. if !ok {
  12. return
  13. }
  14. if len(q) > 0 {
  15. close(q[0])
  16. m.waiters[t] = q[1:]
  17. }
  18. }
  19. func (m *pauseMonitor) append(t string, waiter chan struct{}) {
  20. if m.waiters == nil {
  21. m.waiters = make(map[string][]chan struct{})
  22. }
  23. _, ok := m.waiters[t]
  24. if !ok {
  25. m.waiters[t] = make([]chan struct{}, 0)
  26. }
  27. m.waiters[t] = append(m.waiters[t], waiter)
  28. }