github.com/akerouanton/docker@v1.11.0-rc3/libcontainerd/queue_linux.go (about)

     1  package libcontainerd
     2  
     3  import "sync"
     4  
     5  type queue struct {
     6  	sync.Mutex
     7  	fns map[string]chan struct{}
     8  }
     9  
    10  func (q *queue) append(id string, f func()) {
    11  	q.Lock()
    12  	defer q.Unlock()
    13  
    14  	if q.fns == nil {
    15  		q.fns = make(map[string]chan struct{})
    16  	}
    17  
    18  	done := make(chan struct{})
    19  
    20  	fn, ok := q.fns[id]
    21  	q.fns[id] = done
    22  	go func() {
    23  		if ok {
    24  			<-fn
    25  		}
    26  		f()
    27  		close(done)
    28  	}()
    29  }