MCPcopy
hub / github.com/lxc/incus / Start

Method Start

internal/server/task/group.go:38–72  ·  view source on GitHub ↗

Start all the tasks in the group.

(ctx context.Context)

Source from the content-addressed store, hash-verified

36
37// Start all the tasks in the group.
38func (g *Group) Start(ctx context.Context) {
39 // Lock access to the g.running and g.tasks map for the entirety of this function so that
40 // concurrent calls to Start() or Add(0) don't race. This ensures all tasks in this group
41 // are started based on a consistent snapshot of g.running and g.tasks.
42 g.mu.Lock()
43 defer g.mu.Unlock()
44
45 ctx, g.cancel = context.WithCancel(ctx)
46
47 if g.running == nil {
48 g.running = make(map[int]bool)
49 }
50
51 for i := range g.tasks {
52 if g.running[i] {
53 continue
54 }
55
56 g.running[i] = true
57 task := g.tasks[i] // Local variable for the closure below.
58 g.wg.Add(1)
59
60 go func(i int) {
61 defer g.wg.Done()
62
63 task.loop(ctx)
64
65 // Ensure running map is updated before wait group Done() is called.
66 g.mu.Lock()
67 defer g.mu.Unlock()
68
69 g.running[i] = false
70 }(i)
71 }
72}
73
74// Stop all tasks in the group.
75//

Callers 4

StartFunction · 0.95
TestGroup_AddFunction · 0.95
initMethod · 0.95

Calls 3

loopMethod · 0.80
AddMethod · 0.65
DoneMethod · 0.45

Tested by 2

TestGroup_AddFunction · 0.76