// 投递定时器事件 func (this *AppBase) PostEvent(a help.IEvent) bool { check_name := len(a.GetName()) > 0 if check_name { if _, ok := this.evt_names[a.GetName()]; ok { return false } } if a.GetTouchTime() < 0 { return false } // 计算放在那一层 pos := (a.GetTouchTime() + Evt_gap_time - 1) >> Evt_gap_bit if pos < 0 { pos = 1 } var header *help.DListNode if pos < this.evt_lay1Size { new_pos := this.evt_lay1Cursor + pos if new_pos >= this.evt_lay1Size { new_pos = new_pos - this.evt_lay1Size } pos = new_pos header = &this.evt_lay1[pos] } else { if _, ok := this.evt_lay2[pos]; !ok { this.evt_lay2[pos] = new(help.DListNode) this.evt_lay2[pos].Init(nil) } header = this.evt_lay2[pos] } if header == nil { return false } n := &help.DListNode{} n.Init(a) if !a.AddNode(n) { return false } old_pre := header.Pre header.Pre = n n.Next = header n.Pre = old_pre old_pre.Next = n if check_name { this.evt_names[a.GetName()] = a } return true }
// 节点池 : 增加自由节点 func (this *AppBase) addFreeDlinkNode(n *help.DListNode) { old_pre := this.node_free.Pre this.node_free.Pre = n n.Next = &this.node_free n.Pre = old_pre old_pre.Next = n }
// 节点池 : 释放节点 func (this *AppBase) releaseDlinkNode(d *help.DListNode) { if d == nil || d.Next == nil { return } // 释放一串 if !d.IsEmpty() { header_pre := d.Pre header_next := d.Next d.Init(nil) old_pre := this.node_free.Pre this.node_free.Pre = header_pre header_pre.Next = &this.node_free header_next.Pre = old_pre old_pre.Next = header_next } }