Beispiel #1
0
// 获取线程间消息
func (this *ThreadMsgPool) GetMsg(tid int32, a event.IEvent) bool {
	if !a.IsHeader() {
		return false
	}
	if tid >= jiekou.Tid_master && tid < jiekou.Tid_last {
		this.lock[tid].Lock()
		defer this.lock[tid].Unlock()

		header := this.header[tid]

		header_pre := header.GetPreTimer()
		header_next := header.GetNextTimer()

		header.SetPreTimer(header)
		header.SetNextTimer(header)

		a.GetPreTimer().SetNextTimer(header_pre)
		header_pre.SetPreTimer(a.GetPreTimer())

		a.SetPreTimer(header_next)
		header_next.SetNextTimer(a)

		return true
	}
	return false
}
Beispiel #2
0
// 从线程事件中弹出指定事件, 只能操作本线程事件
func (this *Thread) PopTimer(e event.IEvent) {
	if !e.IsHeader() {
		e.GetPreTimer().SetNextTimer(e.GetNextTimer())
		e.GetNextTimer().SetPreTimer(e.GetPreTimer())
		e.SetNextTimer(nil)
		e.SetPreTimer(nil)
	}
}
Beispiel #3
0
// 投递定时器事件
func (this *Thread) PostEvent(a event.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() + jiekou.Evt_gap_time - 1) >> jiekou.Evt_gap_bit
	if pos < 0 {
		pos = 1
	}

	var header event.IEvent

	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(event.EventHeader)
			this.evt_lay2[pos].Init("", 100)
		}
		header = this.evt_lay2[pos]
	}

	old_pre := header.GetPreTimer()
	header.SetPreTimer(a)
	a.SetNextTimer(header)
	a.SetPreTimer(old_pre)
	old_pre.SetNextTimer(a)

	if check_name {
		this.evt_names[a.GetName()] = a
	}

	return true
}