2
This commit is contained in:
parent
a3412f2da9
commit
7749a036a0
27
timer.go
27
timer.go
@ -1,7 +1,5 @@
|
|||||||
package q5
|
package q5
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
const CONFIG_BASE_SMALL = false
|
const CONFIG_BASE_SMALL = false
|
||||||
const TVN_BITS = 6
|
const TVN_BITS = 6
|
||||||
const TVR_BITS = 8
|
const TVR_BITS = 8
|
||||||
@ -94,7 +92,7 @@ func (this *Timer) Update() {
|
|||||||
this.cascade(&this.tv4, this.getTimerIndex(2)) != 0 {
|
this.cascade(&this.tv4, this.getTimerIndex(2)) != 0 {
|
||||||
this.cascade(&this.tv5, this.getTimerIndex(3))
|
this.cascade(&this.tv5, this.getTimerIndex(3))
|
||||||
}
|
}
|
||||||
this.timerTick += 1
|
this.timerTick++
|
||||||
|
|
||||||
var workList ListHead
|
var workList ListHead
|
||||||
this.tv1[index].ReplaceInit(&workList)
|
this.tv1[index].ReplaceInit(&workList)
|
||||||
@ -111,7 +109,7 @@ func (this *Timer) Update() {
|
|||||||
switch this.runningTimer.timerType {
|
switch this.runningTimer.timerType {
|
||||||
case REPEAT_TIMER, FIXED_TIMER:
|
case REPEAT_TIMER, FIXED_TIMER:
|
||||||
if timer_list.timerType == FIXED_TIMER {
|
if timer_list.timerType == FIXED_TIMER {
|
||||||
timer_list.fixedTimierExecuteTimes += 1
|
timer_list.fixedTimierExecuteTimes++
|
||||||
}
|
}
|
||||||
this.ModifyTimer(timer_list, timer_list.milliSeconds)
|
this.ModifyTimer(timer_list, timer_list.milliSeconds)
|
||||||
case DEADLINE_TIMER:
|
case DEADLINE_TIMER:
|
||||||
@ -205,14 +203,11 @@ func (this *Timer) ModifyTimer(timerList *TimerList, milliSeconds int32) {
|
|||||||
timerList.milliSeconds = milliSeconds
|
timerList.milliSeconds = milliSeconds
|
||||||
if timerList.timerType == FIXED_TIMER {
|
if timerList.timerType == FIXED_TIMER {
|
||||||
tick := this.getTickCount(this.context)
|
tick := this.getTickCount(this.context)
|
||||||
nowTime := time.Now().Unix()
|
timerList.expires = this.getFixedTimerExpires(
|
||||||
todayPassedSeconds := nowTime - GetDaySeconds(nowTime)
|
this.context,
|
||||||
timerList.expires = (tick - todayPassedSeconds * 1000) + int64(milliSeconds)
|
timerList.fixedTimierExecuteTimes,
|
||||||
if timerList.fixedTimierExecuteTimes > 0 {
|
milliSeconds,
|
||||||
if timerList.expires <= tick {
|
tick)
|
||||||
timerList.expires += 1000 * 3600 * 24
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
timerList.expires = this.getTickCount(this.context) + int64(milliSeconds)
|
timerList.expires = this.getTickCount(this.context) + int64(milliSeconds)
|
||||||
}
|
}
|
||||||
@ -250,7 +245,7 @@ func (this *Timer) detachTimer(timerList *TimerList) {
|
|||||||
|
|
||||||
func (this *Timer) addToFreeList(timerList *TimerList) {
|
func (this *Timer) addToFreeList(timerList *TimerList) {
|
||||||
this.freeTimerList.AddTail(&timerList.entry)
|
this.freeTimerList.AddTail(&timerList.entry)
|
||||||
this.freeTimerNum += 1
|
this.freeTimerNum++
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Timer) cascade(tv *[TVN_SIZE]ListHead, index uint32) uint32 {
|
func (this *Timer) cascade(tv *[TVN_SIZE]ListHead, index uint32) uint32 {
|
||||||
@ -307,7 +302,7 @@ func (this *Timer) newTimerList() *TimerList {
|
|||||||
if !this.freeTimerList.Empty() {
|
if !this.freeTimerList.Empty() {
|
||||||
timerList := this.freeTimerList.FirstEntry().(*TimerList)
|
timerList := this.freeTimerList.FirstEntry().(*TimerList)
|
||||||
timerList.entry.DelInit()
|
timerList.entry.DelInit()
|
||||||
this.freeTimerNum -= 1
|
this.freeTimerNum--
|
||||||
return timerList
|
return timerList
|
||||||
} else {
|
} else {
|
||||||
timerList := new(TimerList)
|
timerList := new(TimerList)
|
||||||
@ -317,9 +312,9 @@ func (this *Timer) newTimerList() *TimerList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Timer) gcTimerFunc(params *XParams) {
|
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 := this.freeTimerList.FirstEntry().(*TimerList)
|
||||||
timerList.entry.DelInit()
|
timerList.entry.DelInit()
|
||||||
this.freeTimerNum -= 1
|
this.freeTimerNum--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user