diff --git a/event/event.go b/event/event.go index 00b9fcd..d8bfd33 100644 --- a/event/event.go +++ b/event/event.go @@ -41,7 +41,7 @@ type IEventProcessor interface { addListen(eventType EventType,reciver IEventHandler) removeBindEvent(eventType EventType,reciver IEventHandler) removeListen(eventType EventType,reciver IEventHandler) - GetEventChan() chan *Event + GetEventChan() chan Event } type EventHandler struct { @@ -55,7 +55,7 @@ type EventHandler struct { type EventProcessor struct { - eventChannel chan *Event + eventChannel chan Event locker sync.RWMutex mapListenerEvent map[EventType]map[IEventProcessor]int //监听者信息 @@ -109,7 +109,6 @@ func (handler *EventHandler) Init(processor IEventProcessor){ handler.mapRegEvent =map[EventType]map[IEventProcessor]interface{}{} } - func (processor *EventProcessor) SetEventChannel(channelNum int) bool{ processor.locker.Lock() defer processor.locker.Unlock() @@ -121,7 +120,7 @@ func (processor *EventProcessor) SetEventChannel(channelNum int) bool{ channelNum = DefaultEventChannelLen } - processor.eventChannel = make(chan *Event,channelNum) + processor.eventChannel = make(chan Event,channelNum) return true } @@ -182,6 +181,8 @@ func (processor *EventProcessor) UnRegEventReciverFun(eventType EventType,recive } func (handler *EventHandler) Destroy(){ + handler.locker.Lock() + defer handler.locker.Unlock() for eventTyp,mapEventProcess := range handler.mapRegEvent { if mapEventProcess == nil { continue @@ -193,12 +194,12 @@ func (handler *EventHandler) Destroy(){ } } -func (processor *EventProcessor) GetEventChan() chan *Event{ +func (processor *EventProcessor) GetEventChan() chan Event{ processor.locker.Lock() defer processor.locker.Unlock() if processor.eventChannel == nil { - processor.eventChannel =make(chan *Event,DefaultEventChannelLen) + processor.eventChannel =make(chan Event,DefaultEventChannelLen) } return processor.eventChannel @@ -223,20 +224,17 @@ func (processor *EventProcessor) EventHandler(ev *Event) { } } - - - func (processor *EventProcessor) pushEvent(event *Event){ if len(processor.eventChannel)>=cap(processor.eventChannel){ log.Error("event process channel is full.") return } - processor.eventChannel<-event + processor.eventChannel<-*event } func (processor *EventProcessor) castEvent(event *Event){ - if processor.mapListenerEvent == nil{ + if processor.mapListenerEvent == nil { log.Error("mapListenerEvent not init!") return } diff --git a/service/service.go b/service/service.go index f0bb93d..56a9f40 100644 --- a/service/service.go +++ b/service/service.go @@ -130,7 +130,7 @@ func (s *Service) Run() { if s.profiler!=nil { analyzer = s.profiler.Push(fmt.Sprintf("[Event]%d", int(ev.Type))) } - s.eventProcessor.EventHandler(ev) + s.eventProcessor.EventHandler(&ev) if analyzer!=nil { analyzer.Pop() analyzer = nil