1
This commit is contained in:
parent
7ab75e421e
commit
a3ab521064
22
timer.go
22
timer.go
@ -20,7 +20,7 @@ type Timer struct {
|
||||
runningTimer *TimerList
|
||||
timerTick int64
|
||||
getTickCount func (interface{}) int64
|
||||
getFixedTimerExpires func (interface{}, int32, int32, int64) int64
|
||||
getFixedTimerExpires func (interface{}, bool, int32, int64) int64
|
||||
context interface{}
|
||||
cacheTimerNum int32
|
||||
tv1 [TVR_SIZE]ListHead
|
||||
@ -32,7 +32,7 @@ type Timer struct {
|
||||
|
||||
func (this *Timer) Init(
|
||||
getTickCount func (interface{}) int64,
|
||||
getFixedTimerExpires func (interface{}, int32, int32, int64) int64,
|
||||
getFixedTimerExpires func (interface{}, bool, int32, int64) int64,
|
||||
context interface{},
|
||||
gcTime int32,
|
||||
cacheTimerNum int32) {
|
||||
@ -108,15 +108,9 @@ func (this *Timer) Update() {
|
||||
if this.runningTimer != nil {
|
||||
switch this.runningTimer.timerType {
|
||||
case REPEAT_TIMER, FIXED_TIMER:
|
||||
if timerList.timerType == FIXED_TIMER {
|
||||
timerList.fixedTimierExecuteTimes++
|
||||
}
|
||||
this.ModifyTimer(timerList, timerList.milliSeconds)
|
||||
this.modifyTimerEx(timerList, timerList.milliSeconds, false)
|
||||
case DEADLINE_TIMER:
|
||||
this.detachTimer(timerList)
|
||||
if timerList.attachEntry.Empty() {
|
||||
timerList.attachEntry.DelInit()
|
||||
}
|
||||
this.addToFreeList(timerList)
|
||||
}
|
||||
}
|
||||
@ -198,14 +192,18 @@ func (this *Timer) AddFixedTimerEx(
|
||||
return timerList
|
||||
}
|
||||
|
||||
func (this *Timer) ModifyTimer(timerList *TimerList, milliSeconds int32) {
|
||||
func (this *Timer) ModifyTimer(timerList *TimerList, milliSeconds int32) {
|
||||
this.modifyTimerEx(timerList, milliSeconds, true)
|
||||
}
|
||||
|
||||
func (this *Timer) modifyTimerEx(timerList *TimerList, milliSeconds int32, isFirstAdd bool) {
|
||||
this.detachTimer(timerList)
|
||||
timerList.milliSeconds = milliSeconds
|
||||
if timerList.timerType == FIXED_TIMER {
|
||||
tick := this.getTickCount(this.context)
|
||||
timerList.expires = this.getFixedTimerExpires(
|
||||
this.context,
|
||||
timerList.fixedTimierExecuteTimes,
|
||||
isFirstAdd,
|
||||
milliSeconds,
|
||||
tick)
|
||||
} else {
|
||||
@ -244,6 +242,7 @@ func (this *Timer) detachTimer(timerList *TimerList) {
|
||||
}
|
||||
|
||||
func (this *Timer) addToFreeList(timerList *TimerList) {
|
||||
timerList.Reset()
|
||||
this.freeTimerList.AddTail(&timerList.entry)
|
||||
this.freeTimerNum++
|
||||
}
|
||||
@ -301,7 +300,6 @@ func (this *Timer) getTimerIndex(index uint32) uint32 {
|
||||
func (this *Timer) newTimerList() *TimerList {
|
||||
if !this.freeTimerList.Empty() {
|
||||
timerList := this.freeTimerList.FirstEntry().(*TimerList)
|
||||
timerList.entry.DelInit()
|
||||
this.freeTimerNum--
|
||||
return timerList
|
||||
} else {
|
||||
|
27
timerlist.go
27
timerlist.go
@ -1,16 +1,11 @@
|
||||
package q5
|
||||
|
||||
type ITimerList interface {
|
||||
SetTimerAfterFunc(timer_after_func func(params *XParams))
|
||||
}
|
||||
|
||||
type TimerList struct {
|
||||
entry ListHead
|
||||
attachEntry ListHead
|
||||
timerType int8
|
||||
milliSeconds int32
|
||||
expires int64
|
||||
fixedTimierExecuteTimes int32
|
||||
|
||||
timerFunc func (params *XParams)
|
||||
timerAfterFunc func (params *XParams)
|
||||
@ -24,6 +19,26 @@ func (this *TimerList) InitTimerList(
|
||||
timerFunc func (params *XParams)) {
|
||||
this.timerType = timerType
|
||||
this.milliSeconds = millSeconds
|
||||
this.fixedTimierExecuteTimes = 0
|
||||
this.timerFunc = timerFunc
|
||||
}
|
||||
|
||||
func (this *TimerList) Reset() {
|
||||
if !this.entry.Empty() {
|
||||
this.entry.DelInit()
|
||||
}
|
||||
if !this.attachEntry.Empty() {
|
||||
this.attachEntry.DelInit()
|
||||
}
|
||||
this.timerFunc = nil
|
||||
this.timerAfterFunc = nil
|
||||
this.params.Reset()
|
||||
}
|
||||
|
||||
func (this *TimerList) Init() {
|
||||
this.entry.Init()
|
||||
this.attachEntry.Init()
|
||||
}
|
||||
|
||||
func (this *TimerList) SetTimerAfterFunc(timerAfterFunc func(*XParams)) {
|
||||
this.timerAfterFunc = timerAfterFunc
|
||||
}
|
||||
|
@ -8,6 +8,10 @@ type XParams struct {
|
||||
}
|
||||
|
||||
func (this *XParams) Reset() *XParams {
|
||||
this.Sender.Reset()
|
||||
this.Param1.Reset()
|
||||
this.Param2.Reset()
|
||||
this.Param3.Reset()
|
||||
return this
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user