diff --git a/msgqueue.go b/msgqueue.go index 505c005..684cc59 100644 --- a/msgqueue.go +++ b/msgqueue.go @@ -58,5 +58,34 @@ func (this *msgQueue) UnRegisterCb(handler *MsgHandler) { } func (this *msgQueue) FireEvent(msgId int, args q5.Args) { - + if msgId < 0 || msgId >= len(this.msgHandlers) { + return + } + node := &this.msgHandlers[msgId] + node.lock.Lock() + defer node.lock.Unlock() + node.head.ForEach( + func (data interface{}) bool { + h := data.(*MsgHandler) + if !h.deleted { + h.cb(args) + } else { + h.entry.DelInit() + } + return true + }) + node.addingLock.Lock() + defer node.addingLock.Unlock() + if !node.addingHead.Empty() { + node.addingHead.ForEach( + func (data interface{}) bool { + h := data.(*MsgHandler) + h.entry.DelInit() + if !h.deleted { + node.head.AddTail(&h.entry) + h.cb(args) + } + return true + }) + } }