This commit is contained in:
aozhiwei 2020-10-27 15:42:56 +08:00
parent ef23a486d3
commit 7442ad5d81
3 changed files with 10 additions and 10 deletions

View File

@ -6,10 +6,10 @@ type ListHead struct {
data interface{} data interface{}
} }
func (this *ListHead) Init() { func (this *ListHead) Init(data interface{}) {
this.next = this this.next = this
this.prev = this this.prev = this
this.data = nil this.data = data
} }
func (this *ListHead) Del() { func (this *ListHead) Del() {
@ -36,12 +36,12 @@ func (this *ListHead) Replace(pnew *ListHead) {
pnew.next.prev = pnew pnew.next.prev = pnew
pnew.prev = this.prev pnew.prev = this.prev
pnew.prev.next = pnew pnew.prev.next = pnew
pnew.data = this.data
} }
func (this *ListHead) ReplaceInit(pnew *ListHead) { func (this *ListHead) ReplaceInit(pnew *ListHead) {
this.Replace(pnew) this.Replace(pnew)
this.Init() this.next = this
this.prev = this
} }
func (this *ListHead) Empty() bool { func (this *ListHead) Empty() bool {
@ -50,5 +50,6 @@ func (this *ListHead) Empty() bool {
func (this *ListHead) DelInit() { func (this *ListHead) DelInit() {
this.Del() this.Del()
this.Init() this.next = this
this.prev = this
} }

View File

@ -38,7 +38,7 @@ func (this *Timer) Init(
cacheTimerNum int32) { cacheTimerNum int32) {
initListHeadFunc := func (data interface{}) { initListHeadFunc := func (data interface{}) {
head := data.(*ListHead) head := data.(*ListHead)
head.Init() head.Init(nil)
} }
initListHeadFunc(&this.freeTimerList) initListHeadFunc(&this.freeTimerList)
TraverseArray(&this.tv1, initListHeadFunc) TraverseArray(&this.tv1, initListHeadFunc)
@ -122,7 +122,7 @@ func (this *Timer) Update() {
func (this *Timer) NewTimerAttacher() *TimerAttacher { func (this *Timer) NewTimerAttacher() *TimerAttacher {
attacher := new(TimerAttacher) attacher := new(TimerAttacher)
attacher.timer = this attacher.timer = this
attacher.timers.Init() attacher.timers.Init(nil)
return attacher return attacher
} }

View File

@ -49,8 +49,8 @@ func (this *TimerList) reset() {
} }
func (this *TimerList) init() { func (this *TimerList) init() {
this.entry.Init() this.entry.Init(this)
this.attachEntry.Init() this.attachEntry.Init(this)
} }
func (this *TimerList) SetTimerAfterFunc(timerAfterFunc func(*XParams)) { func (this *TimerList) SetTimerAfterFunc(timerAfterFunc func(*XParams)) {
@ -58,6 +58,5 @@ func (this *TimerList) SetTimerAfterFunc(timerAfterFunc func(*XParams)) {
} }
func (this *TimerList) Attach(timerAttacher *TimerAttacher) { func (this *TimerList) Attach(timerAttacher *TimerAttacher) {
this.attachEntry.data = this
timerAttacher.timers.AddTail(&this.attachEntry) timerAttacher.timers.AddTail(&this.attachEntry)
} }