mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
5425a5ab84
Signed-off-by: yangshukui <yangshukui@huawei.com>
37 lines
473 B
Go
37 lines
473 B
Go
// +build linux solaris
|
|
|
|
package libcontainerd
|
|
|
|
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)
|
|
|
|
q.Lock()
|
|
if q.fns[id] == done {
|
|
delete(q.fns, id)
|
|
}
|
|
q.Unlock()
|
|
}()
|
|
}
|