64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
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 {
|
|
entry ListHead
|
|
attachEntry ListHead
|
|
timerType int8
|
|
milliSeconds int32
|
|
expires int64
|
|
|
|
timerFunc func (params *XParams)
|
|
timerAfterFunc func (params *XParams)
|
|
params XParams
|
|
}
|
|
|
|
func (this *TimerList) InitTimerList(
|
|
timer interface{},
|
|
timerType int8,
|
|
millSeconds int32,
|
|
timerFunc func (params *XParams)) {
|
|
this.timerType = timerType
|
|
this.milliSeconds = millSeconds
|
|
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
|
|
}
|
|
|
|
func (this *TimerList) Attach(timerAttacher *TimerAttacher) {
|
|
this.attachEntry.data = this
|
|
timerAttacher.timers.AddTail(&this.attachEntry)
|
|
}
|