更新 listhead, timer 添加方法 DeleteRunningTimer() 删除当前运行定时器。
This commit is contained in:
parent
72f4aa8132
commit
ef6a02719b
10
listhead.go
10
listhead.go
@ -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 {
|
||||
|
11
timer.go
11
timer.go
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user