pausemonitor_unix.go 714 B

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