This commit is contained in:
aozhiwei 2020-09-08 15:20:32 +08:00
parent a3412f2da9
commit 7749a036a0

View File

@ -1,7 +1,5 @@
package q5
import "time"
const CONFIG_BASE_SMALL = false
const TVN_BITS = 6
const TVR_BITS = 8
@ -94,7 +92,7 @@ func (this *Timer) Update() {
this.cascade(&this.tv4, this.getTimerIndex(2)) != 0 {
this.cascade(&this.tv5, this.getTimerIndex(3))
}
this.timerTick += 1
this.timerTick++
var workList ListHead
this.tv1[index].ReplaceInit(&workList)
@ -111,7 +109,7 @@ func (this *Timer) Update() {
switch this.runningTimer.timerType {
case REPEAT_TIMER, FIXED_TIMER:
if timer_list.timerType == FIXED_TIMER {
timer_list.fixedTimierExecuteTimes += 1
timer_list.fixedTimierExecuteTimes++
}
this.ModifyTimer(timer_list, timer_list.milliSeconds)
case DEADLINE_TIMER:
@ -205,14 +203,11 @@ func (this *Timer) ModifyTimer(timerList *TimerList, milliSeconds int32) {
timerList.milliSeconds = milliSeconds
if timerList.timerType == FIXED_TIMER {
tick := this.getTickCount(this.context)
nowTime := time.Now().Unix()
todayPassedSeconds := nowTime - GetDaySeconds(nowTime)
timerList.expires = (tick - todayPassedSeconds * 1000) + int64(milliSeconds)
if timerList.fixedTimierExecuteTimes > 0 {
if timerList.expires <= tick {
timerList.expires += 1000 * 3600 * 24
}
}
timerList.expires = this.getFixedTimerExpires(
this.context,
timerList.fixedTimierExecuteTimes,
milliSeconds,
tick)
} else {
timerList.expires = this.getTickCount(this.context) + int64(milliSeconds)
}
@ -250,7 +245,7 @@ func (this *Timer) detachTimer(timerList *TimerList) {
func (this *Timer) addToFreeList(timerList *TimerList) {
this.freeTimerList.AddTail(&timerList.entry)
this.freeTimerNum += 1
this.freeTimerNum++
}
func (this *Timer) cascade(tv *[TVN_SIZE]ListHead, index uint32) uint32 {
@ -307,7 +302,7 @@ func (this *Timer) newTimerList() *TimerList {
if !this.freeTimerList.Empty() {
timerList := this.freeTimerList.FirstEntry().(*TimerList)
timerList.entry.DelInit()
this.freeTimerNum -= 1
this.freeTimerNum--
return timerList
} else {
timerList := new(TimerList)
@ -317,9 +312,9 @@ func (this *Timer) newTimerList() *TimerList {
}
func (this *Timer) gcTimerFunc(params *XParams) {
for i := 0; !this.freeTimerList.Empty() && this.freeTimerNum > this.cacheTimerNum && i < 1000; i += 1 {
for i := 0; !this.freeTimerList.Empty() && this.freeTimerNum > this.cacheTimerNum && i < 1000; i++ {
timerList := this.freeTimerList.FirstEntry().(*TimerList)
timerList.entry.DelInit()
this.freeTimerNum -= 1
this.freeTimerNum--
}
}