Fix for crash when unsubscription during event processing (untested)

This commit is contained in:
2016-01-06 13:47:02 +01:00
parent 34cbbb3eb1
commit 49884d7e60
2 changed files with 33 additions and 22 deletions
+6 -2
View File
@@ -13,6 +13,8 @@
relay = decltype(relay)(std::bind(handler, this, std::placeholders::_1)); \
m_EventBroker->Subscribe(relay);
typedef unsigned int EventID;
class EventBroker;
class BaseEventRelay
@@ -31,6 +33,7 @@ public:
virtual bool Receive(const std::shared_ptr<Event> event) = 0;
protected:
EventID m_EventID;
std::string m_ContextTypeName;
std::string m_EventTypeName;
EventBroker* m_Broker;
@@ -95,6 +98,7 @@ public:
private:
bool m_IsProcessing = false;
EventID m_NextEventID = 0;
typedef std::string ContextTypeName_t; // typeid(ContextType).name()
typedef std::string EventTypeName_t; // typeid(EventType).name()
@@ -103,14 +107,14 @@ private:
typedef std::unordered_map<ContextTypeName_t, EventRelays_t> ContextRelays_t;
ContextRelays_t m_ContextRelays;
std::vector<BaseEventRelay*> m_RelaysToSubscribe;
std::vector<BaseEventRelay*> m_RelaysToUnsubscribe;
std::vector<std::tuple<EventID, ContextTypeName_t, EventTypeName_t>> m_RelaysToUnsubscribe;
typedef std::list<std::pair<EventTypeName_t, std::shared_ptr<Event>>> EventQueue_t;
std::shared_ptr<EventQueue_t> m_EventQueueRead;
std::shared_ptr<EventQueue_t> m_EventQueueWrite;
void subscribeImmediate(BaseEventRelay& relay);
void unsubscribeImmediate(BaseEventRelay& relay);
void unsubscribeImmediate(std::tuple<EventID, ContextTypeName_t, EventTypeName_t> identifier);
};
template <typename EventType>