From cc1a26b9820520176ada116f74dc1859cfa4b406 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 8 Sep 2020 16:04:50 +0800 Subject: [PATCH] 1 --- app.go | 35 ++++++++++++++++++++++++----------- syslog.go | 16 +++++++--------- tglog.go | 14 ++++++-------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/app.go b/app.go index 649e77c..5f6b20a 100644 --- a/app.go +++ b/app.go @@ -25,7 +25,20 @@ type App_ struct { func (this *App_) Init() { _Timer = &q5.Timer{} _Timer.Init( - q5.GetTickCount, + func (context interface{}) int64 { + return q5.GetTickCount() + }, + func (context interface{}, fixedTimierExecuteTimes int32, milliSeconds int32, tick int64) int64 { + nowTime := time.Now().Unix() + todayPassedSeconds := nowTime - q5.GetDaySeconds(nowTime) + expires := (tick - todayPassedSeconds * 1000) + int64(milliSeconds) + if fixedTimierExecuteTimes > 0 { + if expires <= tick { + expires += 1000 * 3600 * 24 + } + } + return expires + }, nil, 1000 * 60, 5000) @@ -82,17 +95,16 @@ func (this *App_) AddIMMsg(msgId int16, params *q5.XParams) { p.msgId = msgId p.params = params - { - this.imMsgMutex.Lock() - defer this.imMsgMutex.Unlock() - if this.imBotNode != nil { - this.imBotNode.next = p - this.imBotNode = p - } else { - this.imTopNode = p - this.imBotNode = p - } + this.imMsgMutex.Lock() + if this.imBotNode != nil { + this.imBotNode.next = p + this.imBotNode = p + } else { + this.imTopNode = p + this.imBotNode = p } + this.imMsgMutex.Unlock() + this.loopCond.Broadcast() } @@ -116,3 +128,4 @@ func (this *App_) schedule() { this.loopCond.Wait() this.loopCond.L.Unlock() } + diff --git a/syslog.go b/syslog.go index a14969d..8a85512 100644 --- a/syslog.go +++ b/syslog.go @@ -114,25 +114,23 @@ func (this *SysLog_) goSaveToFile() { select { case <-this.chGoSaveExit: return - case <-time.After(time.Millisecond * 1000 * 10): - } - { - this.msgMutex.Lock() - defer this.msgMutex.Unlock() - workNode = this.topNode - this.topNode = nil - this.botNode = nil + case <-time.After(time.Millisecond * 10): } + this.msgMutex.Lock() + workNode = this.topNode + this.topNode = nil + this.botNode = nil + this.msgMutex.Unlock() if workNode != nil { logDir := fmt.Sprintf(SYS_LOG_ROOT, App.GetPkgName()) fileName := fmt.Sprintf(TGLOG_FILENAME, os.Getpid(), time.Now().Format("20060102")) q5.ForceCreateDir(logDir) if f, err := os.OpenFile(logDir + fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666); err == nil { - defer f.Close() for workNode != nil { f.Write([]byte(workNode.logMsg)) workNode = workNode.next } + f.Close() } else { fmt.Println(err) } diff --git a/tglog.go b/tglog.go index 7109d75..1134c42 100644 --- a/tglog.go +++ b/tglog.go @@ -80,19 +80,17 @@ func (this *TGLog_) goSaveToFile() { return case <-time.After(time.Millisecond * 1000 * 10): } - { - this.msgMutex.Lock() - defer this.msgMutex.Unlock() - workNode = this.topNode - this.topNode = nil - this.botNode = nil - } + this.msgMutex.Lock() + workNode = this.topNode + this.topNode = nil + this.botNode = nil + this.msgMutex.Unlock() if workNode != nil { for workNode != nil { f := this.getLogFile(workNode.gameId) if f != nil { - defer f.Close() f.Write([]byte(workNode.jsonStr + "\n")) + f.Close() } workNode = workNode.next }