This commit is contained in:
aozhiwei 2024-11-06 14:14:39 +08:00
parent a8bed347a7
commit 764ec9224d

View File

@ -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
})
}
}