MCPcopy Create free account
hub / github.com/Cyinx/einx / Run

Method Run

module/module.go:156–212  ·  view source on GitHub ↗
(wait *sync.WaitGroup)

Source from the content-addressed store, hash-verified

154}
155
156func (this *module) Run(wait *sync.WaitGroup) {
157 runtime.LockOSThread()
158 defer this.recover(wait)
159 wait.Add(1)
160 defer wait.Done()
161 this.begin_time = time.Now().UnixNano() / 1e9
162 timer_manager := this.timer_manager
163 var (
164 event_msg EventMsg = nil
165 close_flag bool = false
166 ev_queue = this.ev_queue
167 event_chan = ev_queue.SemaChan()
168 timer_tick = time.NewTimer(time.Duration(MODULE_TIMER_INTERVAL) * time.Millisecond)
169 tick_c = timer_tick.C
170 nextWake = 0
171 event_list = this.event_list
172 )
173
174 for {
175 for {
176 if this.event_index >= this.event_count {
177 this.event_count = ev_queue.Get(event_list, uint32(MODULE_EVENT_LENGTH))
178 this.event_index = 0
179 }
180 for this.event_index < this.event_count {
181 event_msg = event_list[this.event_index].(EventMsg)
182 event_list[this.event_index] = nil
183 this.event_index++
184 this.handle_event(event_msg)
185 this.op_count++
186 }
187 nextWake = timer_manager.Execute(100)
188 if this.event_count <= 0 && nextWake > 0 {
189 break
190 }
191 }
192
193 if ev_queue.WaitNotify() == false {
194 continue
195 }
196
197 timer_tick.Reset(time.Duration(nextWake) * time.Millisecond)
198 select {
199 case close_flag = <-this.close_chan:
200 if close_flag == true {
201 goto run_close
202 }
203 case <-event_chan:
204 case <-tick_c:
205 }
206
207 ev_queue.WaiterWake()
208 }
209
210run_close:
211 this.do_close(wait)
212}
213

Callers 1

recoverMethod · 0.95

Calls 9

recoverMethod · 0.95
handle_eventMethod · 0.95
do_closeMethod · 0.95
SemaChanMethod · 0.80
ExecuteMethod · 0.80
WaitNotifyMethod · 0.80
WaiterWakeMethod · 0.80
GetMethod · 0.65
ResetMethod · 0.65

Tested by

no test coverage detected