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

		header := this.header[tid]

		a_pre := a.GetPreTimer()
		a_next := a.GetNextTimer()

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

		header.GetPreTimer().SetNextTimer(a_pre)
		a_pre.SetPreTimer(header.GetPreTimer())

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

		return true
	}
	return false
}
Example #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)
	}
}
Example #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
}
Example #4
0
// 投递线程间消息
func (this *Thread) PostThreadMsg(tid int32, a event.IEvent) bool {
	if tid == this.Get_thread_id() {
		fmt.Printf("[W] %d post msg failed\n", tid)
		return false
	}
	if tid >= jiekou.Tid_master && tid < jiekou.Tid_last {
		header := this.evt_threadMsg[tid]
		old_pre := header.GetPreTimer()
		header.SetPreTimer(a)
		a.SetNextTimer(header)
		a.SetPreTimer(old_pre)
		old_pre.SetNextTimer(a)

		return true
	}
	fmt.Printf("[W] %d post msg failed2\n", tid)
	return false
}