From: g0dil Date: Wed, 15 Sep 2010 15:32:25 +0000 (+0000) Subject: Packets: Fix global registry destruction segfault X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=cd804c6da24eedea11475ae76c1fb5c513073181;p=senf.git Packets: Fix global registry destruction segfault git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1717 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/PacketRegistry.ct b/senf/Packets/PacketRegistry.ct index 6237734..b2c6501 100644 --- a/senf/Packets/PacketRegistry.ct +++ b/senf/Packets/PacketRegistry.ct @@ -86,17 +86,6 @@ senf::detail::PacketRegistryImpl::EntryImpl::type() } /////////////////////////////////////////////////////////////////////////// -// senf::PacketRegistry - -template -prefix_ typename senf::PacketRegistry::Registry & -senf::PacketRegistry::registry() -{ - static Registry registry (prettyName(typeid(Tag))); - return registry; -} - -/////////////////////////////////////////////////////////////////////////// // senf::detail::PacketRegistryImpl: template diff --git a/senf/Packets/PacketRegistry.cti b/senf/Packets/PacketRegistry.cti index b70af2a..44ee816 100644 --- a/senf/Packets/PacketRegistry.cti +++ b/senf/Packets/PacketRegistry.cti @@ -66,13 +66,15 @@ template template prefix_ void senf::PacketRegistry::unregisterPacket() { - registry().unregisterPacket(); + if (alive()) + registry().unregisterPacket(); } template prefix_ void senf::PacketRegistry::unregisterPacket(typename Tag::key_t key, int priority) { - registry().unregisterPacket(key, priority); + if (alive()) + registry().unregisterPacket(key, priority); } template @@ -128,6 +130,18 @@ prefix_ typename senf::PacketRegistry::iterator senf::PacketRegistry:: return registry().end(); } +template +prefix_ senf::PacketRegistry::PacketRegistry() + : registry_ (prettyName(typeid(Tag))) +{} + +template +prefix_ typename senf::PacketRegistry::Registry & +senf::PacketRegistry::registry() +{ + return instance().registry_; +} + /////////////////////////////////////////////////////////////////////////// // senf::detail::PacketRegistryImpl diff --git a/senf/Packets/PacketRegistry.hh b/senf/Packets/PacketRegistry.hh index 868d485..1f748a1 100644 --- a/senf/Packets/PacketRegistry.hh +++ b/senf/Packets/PacketRegistry.hh @@ -32,6 +32,7 @@ #include #include #include +#include #include "Packet.hh" #include "PacketRegistry.ih" @@ -86,6 +87,7 @@ namespace senf { */ template class PacketRegistry + : private senf::singleton< PacketRegistry > { public: typedef typename detail::PacketRegistryImpl::iterator iterator; @@ -219,8 +221,16 @@ namespace senf { static iterator end(); private: + using singleton::instance; + using singleton::alive; + + PacketRegistry(); + typedef detail::PacketRegistryImpl Registry; static Registry & registry(); + Registry registry_; + + friend class senf::singleton< PacketRegistry >; }; /** \brief Statically add an entry to a packet registry