更新 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) {
|
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 := ListHead{}
|
||||||
cursor.data = &cursor
|
cursor.data = &cursor
|
||||||
this.AddHead(&cursor)
|
this.AddHead(&cursor)
|
||||||
defer cursor.Del()
|
defer cursor.Del()
|
||||||
for ; cursor.next != this; {
|
for cursor.next != this {
|
||||||
oldN := cursor.next
|
oldN := cursor.next
|
||||||
if !cursor.next.isCursor() && !cb(cursor.next.data) {
|
if !cursor.next.isCursor() && !cb(cursor.next.data) {
|
||||||
break
|
break
|
||||||
@ -117,7 +123,7 @@ func (this *ListHead) ForEach(cb ListHead_Foreach_Func) {
|
|||||||
oldN.Del()
|
oldN.Del()
|
||||||
cursor.AddTail(oldN)
|
cursor.AddTail(oldN)
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewListHead() *ListHead {
|
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 {
|
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 {
|
func (this *XTimer) newTimerList() *XTimerList {
|
||||||
@ -322,7 +322,7 @@ func (this *XTimer) newTimerList() *XTimerList {
|
|||||||
func (this *XTimer) gcTimerFunc(ev int32, args *Args) {
|
func (this *XTimer) gcTimerFunc(ev int32, args *Args) {
|
||||||
if ev == TIMER_EXEC_EVENT {
|
if ev == TIMER_EXEC_EVENT {
|
||||||
count := 0
|
count := 0
|
||||||
for ; !this.freeTimerList.Empty() && this.freeTimerNum > this.cacheTimerNum; {
|
for !this.freeTimerList.Empty() && this.freeTimerNum > this.cacheTimerNum {
|
||||||
timerList := this.freeTimerList.FirstEntry().(*XTimerList)
|
timerList := this.freeTimerList.FirstEntry().(*XTimerList)
|
||||||
timerList.entry.DelInit()
|
timerList.entry.DelInit()
|
||||||
this.freeTimerNum--
|
this.freeTimerNum--
|
||||||
@ -380,3 +380,10 @@ func (this *XTimer) clearAttacher(attacher* XTimerAttacher) {
|
|||||||
this.internalDelete(timer, false, true)
|
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() {
|
func (this *XTimerList) init() {
|
||||||
this.entry.Init(this)
|
this.entry.Init(this)
|
||||||
this.attachEntry.Init(this)
|
this.attachEntry.Init(this)
|
||||||
|
this.destoryHandleList.Init(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *XTimerList) Attach(timerAttacher *XTimerAttacher) {
|
func (this *XTimerList) Attach(timerAttacher *XTimerAttacher) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user