Browse Source

Prevent handles call on shutdown

cl-refactor
arkpar 10 years ago
parent
commit
1d5a25991d
  1. 12
      libethcore/Common.h

12
libethcore/Common.h

@ -157,7 +157,8 @@ public:
~Signal() ~Signal()
{ {
for (auto const& h : m_fire) for (auto const& h : m_fire)
h.second->reset(); if (auto l = h.second.lock())
l->reset();
} }
std::shared_ptr<HandlerAux> add(Callback const& _h) std::shared_ptr<HandlerAux> add(Callback const& _h)
@ -168,10 +169,15 @@ public:
return h; return h;
} }
void operator()(Args&... _args) { for (auto const& f: m_fire) f.second->fire(std::forward<Args>(_args)...); } void operator()(Args&... _args)
{
for (auto const& f: m_fire)
if (auto h = f.second.lock())
h->fire(std::forward<Args>(_args)...);
}
private: private:
std::map<unsigned, std::shared_ptr<typename Signal::HandlerAux>> m_fire; std::map<unsigned, std::weak_ptr<typename Signal::HandlerAux>> m_fire;
}; };
template<class... Args> using Handler = std::shared_ptr<typename Signal<Args...>::HandlerAux>; template<class... Args> using Handler = std::shared_ptr<typename Signal<Args...>::HandlerAux>;

Loading…
Cancel
Save