1
This commit is contained in:
parent
169414f01e
commit
8d7bf727ef
11
app.go
11
app.go
@ -21,6 +21,7 @@ type App_ struct {
|
||||
imWorkNode *IMMsgNode
|
||||
imMsgMutex sync.RWMutex
|
||||
chGoLoopTimerExit chan int
|
||||
chGoLoopWait chan int64
|
||||
nowTime time.Time
|
||||
imMsgHandlers [1024]func(int16,*q5.XParams)
|
||||
}
|
||||
@ -53,6 +54,7 @@ func (this *App_) Init() {
|
||||
flag.Parse()
|
||||
this.loopCond = sync.NewCond(new(sync.Mutex))
|
||||
this.chGoLoopTimerExit = make(chan int)
|
||||
this.chGoLoopWait = make(chan int64)
|
||||
go this.goLoopTimer()
|
||||
}
|
||||
|
||||
@ -118,17 +120,24 @@ func (this *App_) RegisterIMMsgHandle(msgId int16, handle func(int16,*q5.XParams
|
||||
}
|
||||
|
||||
func (this *App_) goLoopTimer() {
|
||||
var waitMs int64 = 1000 * 10
|
||||
for {
|
||||
select {
|
||||
case <-this.chGoLoopTimerExit:
|
||||
return
|
||||
case <-time.After(time.Millisecond):
|
||||
case waitMs = <-this.chGoLoopWait:
|
||||
if waitMs < 1 {
|
||||
waitMs = 1
|
||||
}
|
||||
case <-time.After(time.Millisecond * time.Duration(waitMs)):
|
||||
waitMs = 1000 * 10
|
||||
this.loopCond.Broadcast()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *App_) schedule() {
|
||||
this.chGoLoopWait <- Timer().GetIdleTime()
|
||||
this.loopCond.L.Lock()
|
||||
this.loopCond.Wait()
|
||||
this.loopCond.L.Unlock()
|
||||
|
Loading…
x
Reference in New Issue
Block a user