Example #1
0
// Copy the message data to the out-queue.
func (p *Pumper) PostOut(id MsgId, m Msg) {
	p.newerLock.RLock()
	defer p.newerLock.RUnlock()
	if p.newer != nil {
		p.newer.PostOut(id, m)
	} else {
		cp := poolutil.BufGet(len(m))
		copy(cp, m)
		p.pushWMsg(id, cp)
	}
}
Example #2
0
// Inherit inner data from the old pumper.
// The old pumper must have stopped.
func (p *Pumper) Inherit(older *Pumper, reOutN int) bool {
	op := older
	op.newerLock.Lock()
	defer op.newerLock.Unlock()

	if reOutN > op.bI.Len() {
		return false
	}

	op.rQ.Lock()
	defer op.rQ.Unlock()
	op.wQ.Lock()
	defer op.wQ.Unlock()

	p.rQ.Lock()
	defer p.rQ.Unlock()
	p.wQ.Lock()
	defer p.wQ.Unlock()

	// in
	p.rQ.List().MergeFrontList(op.rQ.List())

	// backup
	useless := op.bI.Len() - reOutN
	for i := 0; i < useless; i++ {
		_, l := op.bI.PopFront()
		op.bB.Skip(l)
	}
	for i := 0; i < reOutN; i++ {
		id, l := op.bI.PopFront()
		m := poolutil.BufGet(l)
		op.bB.Read(m)
		p.wQ.List().PushBack(newMsgEntry(id, m))
	}

	// out
	p.wQ.List().MergeBackList(op.wQ.List())

	op.newer = p

	p.rQ.SetEvent()
	p.wQ.SetEvent()

	return true
}