更新 listhead, timer 添加方法 DeleteRunningTimer() 删除当前运行定时器。

This commit is contained in:
殷勇 2023-10-23 11:50:27 +08:00
parent 72f4aa8132
commit ef6a02719b
3 changed files with 68 additions and 54 deletions

View File

@ -104,11 +104,17 @@ func (this *ListHead) isCursor() bool {
}
func (this *ListHead) ForEach(cb ListHead_Foreach_Func) {
for pos := this.next; pos != this; pos = pos.next {
if !cb(pos.data) {
break
}
}
/*
cursor := ListHead{}
cursor.data = &cursor
this.AddHead(&cursor)
defer cursor.Del()
for ; cursor.next != this; {
for cursor.next != this {
oldN := cursor.next
if !cursor.next.isCursor() && !cb(cursor.next.data) {
break
@ -117,7 +123,7 @@ func (this *ListHead) ForEach(cb ListHead_Foreach_Func) {
oldN.Del()
cursor.AddTail(oldN)
}
}
}*/
}
func NewListHead() *ListHead {

View File

@ -304,7 +304,7 @@ func (this *XTimer) internalAddTimer(timerList *XTimerList) {
}
func (this *XTimer) getTimerIndex(index uint32) uint32 {
return (uint32)((this.timerTick >> (TVR_BITS + index * TVN_BITS)) & TVN_MASK);
return (uint32)((this.timerTick >> (TVR_BITS + index*TVN_BITS)) & TVN_MASK)
}
func (this *XTimer) newTimerList() *XTimerList {
@ -322,7 +322,7 @@ func (this *XTimer) newTimerList() *XTimerList {
func (this *XTimer) gcTimerFunc(ev int32, args *Args) {
if ev == TIMER_EXEC_EVENT {
count := 0
for ; !this.freeTimerList.Empty() && this.freeTimerNum > this.cacheTimerNum; {
for !this.freeTimerList.Empty() && this.freeTimerNum > this.cacheTimerNum {
timerList := this.freeTimerList.FirstEntry().(*XTimerList)
timerList.entry.DelInit()
this.freeTimerNum--
@ -380,3 +380,10 @@ func (this *XTimer) clearAttacher(attacher* XTimerAttacher) {
this.internalDelete(timer, false, true)
}
}
func (this *XTimer) DeleteRunningTimer() {
if this.runningTimer != nil {
this.internalDelete(this.runningTimer, false, true)
this.runningTimer = nil
}
}

View File

@ -52,6 +52,7 @@ func (this *XTimerList) reset() {
func (this *XTimerList) init() {
this.entry.Init(this)
this.attachEntry.Init(this)
this.destoryHandleList.Init(nil)
}
func (this *XTimerList) Attach(timerAttacher *XTimerAttacher) {