1
2
3
4
5
12 package main
13
14 import (
15 "os"
16 "runtime"
17 "runtime/pprof"
18 "sync"
19 "time"
20 )
21
22 func init() {
23 register("Moby28462", Moby28462)
24 }
25
26 type State_moby28462 struct {
27 Health *Health_moby28462
28 }
29
30 type Container_moby28462 struct {
31 sync.Mutex
32 State *State_moby28462
33 }
34
35 func (ctr *Container_moby28462) start() {
36 go ctr.waitExit()
37 }
38 func (ctr *Container_moby28462) waitExit() {
39
40 }
41
42 type Store_moby28462 struct {
43 ctr *Container_moby28462
44 }
45
46 func (s *Store_moby28462) Get() *Container_moby28462 {
47 return s.ctr
48 }
49
50 type Daemon_moby28462 struct {
51 containers Store_moby28462
52 }
53
54 func (d *Daemon_moby28462) StateChanged() {
55 c := d.containers.Get()
56 c.Lock()
57 d.updateHealthMonitorElseBranch(c)
58 defer c.Unlock()
59 }
60
61 func (d *Daemon_moby28462) updateHealthMonitorIfBranch(c *Container_moby28462) {
62 h := c.State.Health
63 if stop := h.OpenMonitorChannel(); stop != nil {
64 go monitor_moby28462(c, stop)
65 }
66 }
67 func (d *Daemon_moby28462) updateHealthMonitorElseBranch(c *Container_moby28462) {
68 h := c.State.Health
69 h.CloseMonitorChannel()
70 }
71
72 type Health_moby28462 struct {
73 stop chan struct{}
74 }
75
76 func (s *Health_moby28462) OpenMonitorChannel() chan struct{} {
77 return s.stop
78 }
79
80 func (s *Health_moby28462) CloseMonitorChannel() {
81 if s.stop != nil {
82 s.stop <- struct{}{}
83 }
84 }
85
86 func monitor_moby28462(c *Container_moby28462, stop chan struct{}) {
87 for {
88 select {
89 case <-stop:
90 return
91 default:
92 handleProbeResult_moby28462(c)
93 }
94 }
95 }
96
97 func handleProbeResult_moby28462(c *Container_moby28462) {
98 runtime.Gosched()
99 c.Lock()
100 defer c.Unlock()
101 }
102
103 func NewDaemonAndContainer_moby28462() (*Daemon_moby28462, *Container_moby28462) {
104 c := &Container_moby28462{
105 State: &State_moby28462{&Health_moby28462{make(chan struct{})}},
106 }
107 d := &Daemon_moby28462{Store_moby28462{c}}
108 return d, c
109 }
110
111 func Moby28462() {
112 prof := pprof.Lookup("goroutineleak")
113 defer func() {
114 time.Sleep(100 * time.Millisecond)
115 prof.WriteTo(os.Stdout, 2)
116 }()
117
118 for i := 0; i < 100; i++ {
119 go func() {
120 d, c := NewDaemonAndContainer_moby28462()
121 go monitor_moby28462(c, c.State.Health.OpenMonitorChannel())
122 go d.StateChanged()
123 }()
124 }
125 }
126
View as plain text