blob: ca44a27f74c5dd003c8106a979b35ad887d3b3a5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package libpod
import (
"time"
)
func (r *Runtime) startWorker() {
if r.workerChannel == nil {
r.workerChannel = make(chan func(), 1)
r.workerShutdown = make(chan bool)
}
go func() {
for {
// Make sure to read all workers before
// checking if we're about to shutdown.
for len(r.workerChannel) > 0 {
w := <-r.workerChannel
w()
}
select {
// We'll read from the shutdown channel only when all
// items above have been processed.
//
// (*Runtime).Shutdown() will block until until the
// item is read.
case <-r.workerShutdown:
return
default:
time.Sleep(100 * time.Millisecond)
}
}
}()
}
func (r *Runtime) queueWork(f func()) {
go func() {
r.workerChannel <- f
}()
}
|