pausemonitor_linux.go 694 B

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