This commit is contained in:
aozhiwei 2020-09-08 17:36:26 +08:00
parent a3ab521064
commit e0ae331d17
2 changed files with 45 additions and 11 deletions

View File

@ -213,22 +213,37 @@ func (this *Timer) modifyTimerEx(timerList *TimerList, milliSeconds int32, isFir
} }
func (this *Timer) DeleteTimer(timerList *TimerList) { func (this *Timer) DeleteTimer(timerList *TimerList) {
if timerList == nil {
return
}
if this.runningTimer == timerList {
this.runningTimer = nil
}
if timerList.timerAfterFunc != nil {
timerList.timerAfterFunc(&timerList.params)
}
this.detachTimer(timerList)
this.addToFreeList(timerList)
} }
func (this *Timer) GetTimerByAtttach(attachEntry *ListHead) *TimerList { func (this *Timer) GetTimerByAtttach(attachEntry *ListHead) *TimerList {
return nil return nil
} }
func (this *Timer) MutableParams(timerList *TimerList) *XParams {
return nil
}
func (this *Timer) GetRemainTime(timerList *TimerList) int64 { func (this *Timer) GetRemainTime(timerList *TimerList) int64 {
if timerList == nil {
return 0 return 0
}
remainTime := timerList.expires - this.getTickCount(this.context)
if remainTime < 0 {
return 0
} else {
return remainTime
}
} }
func (this *Timer) GetRunningTimer() *TimerList { func (this *Timer) GetRunningTimer() *TimerList {
return nil return this.runningTimer
} }
func (this *Timer) GetIdleMilliSeconds() int64 { func (this *Timer) GetIdleMilliSeconds() int64 {
@ -264,9 +279,9 @@ func (this *Timer) cascade(tv *[TVN_SIZE]ListHead, index uint32) uint32 {
return index return index
} }
func (this *Timer) internalAddTimer(timer_list *TimerList) { func (this *Timer) internalAddTimer(timerList *TimerList) {
timer_list.entry.data = timer_list timerList.entry.data = timerList
expires := timer_list.expires expires := timerList.expires
idx := expires - this.timerTick idx := expires - this.timerTick
var vec *ListHead var vec *ListHead
var index uint32 var index uint32
@ -290,7 +305,7 @@ func (this *Timer) internalAddTimer(timer_list *TimerList) {
index = (uint32)((expires >> (TVR_BITS + 3 * TVN_BITS)) & TVN_MASK) index = (uint32)((expires >> (TVR_BITS + 3 * TVN_BITS)) & TVN_MASK)
vec = &this.tv5[index] vec = &this.tv5[index]
} }
vec.AddTail(&timer_list.entry) vec.AddTail(&timerList.entry)
} }
func (this *Timer) getTimerIndex(index uint32) uint32 { func (this *Timer) getTimerIndex(index uint32) uint32 {
@ -304,7 +319,7 @@ func (this *Timer) newTimerList() *TimerList {
return timerList return timerList
} else { } else {
timerList := new(TimerList) timerList := new(TimerList)
timerList.entry.Init() timerList.Init()
return timerList return timerList
} }
} }

View File

@ -1,5 +1,19 @@
package q5 package q5
type TimerAttacher struct {
timer *Timer
timers ListHead
}
func (this *TimerAttacher) ClearTimers() {
var workList ListHead
this.timers.ReplaceInit(&workList)
for !workList.Empty() {
timerList := workList.FirstEntry().(*TimerList)
this.timer.DeleteTimer(timerList)
}
}
type TimerList struct { type TimerList struct {
entry ListHead entry ListHead
attachEntry ListHead attachEntry ListHead
@ -42,3 +56,8 @@ func (this *TimerList) Init() {
func (this *TimerList) SetTimerAfterFunc(timerAfterFunc func(*XParams)) { func (this *TimerList) SetTimerAfterFunc(timerAfterFunc func(*XParams)) {
this.timerAfterFunc = timerAfterFunc this.timerAfterFunc = timerAfterFunc
} }
func (this *TimerList) Attach(timerAttacher *TimerAttacher) {
this.attachEntry.data = this
timerAttacher.timers.AddTail(&this.attachEntry)
}