From 9c2949041aafd4ceb4ef2e3e10383e33cfe66016 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 26 Apr 2024 13:24:30 +0800 Subject: [PATCH] 1 --- app.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index 8cee423..46d6c8f 100644 --- a/app.go +++ b/app.go @@ -43,6 +43,7 @@ type App interface { type UserApp interface { GetPkgName() string + HasTask() bool Init() Update() UnInit() @@ -262,10 +263,12 @@ func (this *app) goLoopTimer() { } func (this *app) schedule() { - this.chGoLoopWait <- GetTimer().GetIdleTime() - this.loopCond.L.Lock() - this.loopCond.Wait() - this.loopCond.L.Unlock() + if !this.hasTask() { + this.chGoLoopWait <- GetTimer().GetIdleTime() + this.loopCond.L.Lock() + this.loopCond.Wait() + this.loopCond.L.Unlock() + } } func (this *app) NotifyLoopCond() { @@ -425,6 +428,19 @@ func (this *app) clearEmptyPendingAsyncTask(key string) { } } +func (this *app) hasTask() bool { + hasTask := false + { + this.imMsgMutex.Lock() + hasTask = this.imTopNode != nil || this.imWorkNode != nil + this.imMsgMutex.Unlock() + } + if !hasTask { + hasTask = this.userApp.HasTask() + } + return hasTask +} + func parseArgs() (int, int) { args := os.Args[1:] if len(args) <= 0 {