2018-02-05 16:05:59 -05:00
|
|
|
package libcontainerd // import "github.com/docker/docker/libcontainerd"
|
2016-03-18 14:50:19 -04:00
|
|
|
|
|
|
|
import "sync"
|
|
|
|
|
|
|
|
type queue struct {
|
|
|
|
sync.Mutex
|
|
|
|
fns map[string]chan struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *queue) append(id string, f func()) {
|
|
|
|
q.Lock()
|
|
|
|
defer q.Unlock()
|
|
|
|
|
|
|
|
if q.fns == nil {
|
|
|
|
q.fns = make(map[string]chan struct{})
|
|
|
|
}
|
|
|
|
|
|
|
|
done := make(chan struct{})
|
|
|
|
|
|
|
|
fn, ok := q.fns[id]
|
|
|
|
q.fns[id] = done
|
|
|
|
go func() {
|
|
|
|
if ok {
|
|
|
|
<-fn
|
|
|
|
}
|
|
|
|
f()
|
|
|
|
close(done)
|
2017-06-22 04:47:47 -04:00
|
|
|
|
|
|
|
q.Lock()
|
|
|
|
if q.fns[id] == done {
|
|
|
|
delete(q.fns, id)
|
|
|
|
}
|
|
|
|
q.Unlock()
|
2016-03-18 14:50:19 -04:00
|
|
|
}()
|
|
|
|
}
|