2016-06-07 03:45:21 -04:00
|
|
|
// +build !windows
|
|
|
|
|
2016-03-18 14:50:19 -04:00
|
|
|
package libcontainerd
|
|
|
|
|
2016-09-19 03:42:21 -04:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2016-03-18 14:50:19 -04:00
|
|
|
// pauseMonitor is helper to get notifications from pause state changes.
|
|
|
|
type pauseMonitor struct {
|
2016-09-19 03:42:21 -04:00
|
|
|
sync.Mutex
|
2016-03-18 14:50:19 -04:00
|
|
|
waiters map[string][]chan struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *pauseMonitor) handle(t string) {
|
2016-09-19 03:42:21 -04:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2016-03-18 14:50:19 -04:00
|
|
|
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{}) {
|
2016-09-19 03:42:21 -04:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2016-03-18 14:50:19 -04:00
|
|
|
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)
|
|
|
|
}
|