github.com/kinvolk/docker@v1.13.1/libcontainerd/queue_unix.go (about)

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