From ed3e640b8e2f566483b98445e29e1137452fa013 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 7 Sep 2020 19:29:37 +0800 Subject: [PATCH] 1 --- app.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index 2df5d03..0678b1d 100644 --- a/app.go +++ b/app.go @@ -12,12 +12,13 @@ type App_ struct { flags map[int32]int32 servicing bool contextHash map[int32]q5.XParams - loopCond sync.Cond + loopCond *sync.Cond imTopNode *IMMsgNode imBotNode *IMMsgNode imWorkNode *IMMsgNode imMsgMutex sync.RWMutex chGoLoopTimerExit chan int + imMsgHandlers [1024]func(int16,*q5.XParams) } func (this *App_) Init() { @@ -30,6 +31,7 @@ func (this *App_) Init() { flag.IntVar(&this.nodeId, "n", 0, "node id") flag.IntVar(&this.instanceId, "i", 0, "instance id") flag.Parse() + this.loopCond = sync.NewCond(new(sync.Mutex)) this.chGoLoopTimerExit = make(chan int) go this.goLoopTimer() } @@ -43,7 +45,7 @@ func (this *App_) UnInit() { func (this *App_) Run() { for !this.terminated { _Timer.Update() - this.loopCond.Wait() + this.schedule() } } @@ -84,6 +86,7 @@ func (this *App_) AddIMMsg(msgId int16, params *q5.XParams) { } func (this *App_) RegisterIMMsgHandle(msgId int16, handle func(int16,*q5.XParams)) { + this.imMsgHandlers[msgId] = handle } func (this *App_) goLoopTimer() { @@ -96,3 +99,9 @@ func (this *App_) goLoopTimer() { } } } + +func (this *App_) schedule() { + this.loopCond.L.Lock() + this.loopCond.Wait() + this.loopCond.L.Unlock() +}