queue_linux.go 373 B

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