From 250bfeaee5acc4f6114dfa61cd6203702ae222a5 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 6 Nov 2010 22:56:17 +0100 Subject: [PATCH] use the new OptionalRef to protect session shutdown The original version was sensible to static initialisation order, which shold be resolved now, because of OptionalLink's dtor explicitly disabling any further access. --- src/lib/element-tracker.hpp | 28 +++++++++------------------- src/proc/asset/sequence.cpp | 2 +- src/proc/asset/timeline.cpp | 2 +- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/lib/element-tracker.hpp b/src/lib/element-tracker.hpp index 2b72c0f1d..4513ae379 100644 --- a/src/lib/element-tracker.hpp +++ b/src/lib/element-tracker.hpp @@ -41,8 +41,10 @@ ** @warning AutoRegistered does not check accessibility of the configured ** registry, when detaching an element. Especially, when detaching in turn ** gets automatically invoked from some kind of cleanup, care has to be taken - ** to ensure the registry is still available. Ignoring this might lead to - ** segfault on application shutdown. ///TICKET #574 + ** to ensure the registry is still available. The Functions + ** AutoRegistered::is_attached_to and AutoRegistered::deactivateRegistryLink + ** can be used for detaching an Registry explicitly before destruction. + ** Ignoring this might lead to segfault on application shutdown. /////////////////TICKET #574 ** ** @see session-element-tracker-test.cpp ** @see session-interface-modules.hpp @@ -56,18 +58,15 @@ #define LIB_ELEMENT_TRACKER_H #include "lib/p.hpp" -#include "lib/wrapper.hpp" +#include "lib/optional-ref.hpp" #include "lib/util-foreach.hpp" #include "lib/ref-array-impl.hpp" -#include - namespace lib { using lumiera::P; - using std::tr1::function; using util::isSameObject; /** @@ -173,7 +172,7 @@ namespace lib { { public: typedef lib::ElementTracker Registry; - typedef function RegistryLink; + typedef lib::OptionalRef RegistryLink; /** detach this element * from the element-tracking registry. @@ -210,31 +209,22 @@ namespace lib { } - template - static void - establishRegistryLink (FUN link) - { - AutoRegistered::getRegistry = link; - } - static void setRegistryInstance (Registry& registry_to_use) { - RegistryLink accessInstance = wrapper::refFunction(registry_to_use); - establishRegistryLink (accessInstance); + getRegistry.link_to (registry_to_use); } static void deactivateRegistryLink() { - getRegistry = RegistryLink(); // empty accessor function + getRegistry.clear(); } static bool is_attached_to (Registry const& someRegistry) { - return bool(getRegistry) - && isSameObject (someRegistry, getRegistry()); + return getRegistry.points_to (someRegistry); } protected: diff --git a/src/proc/asset/sequence.cpp b/src/proc/asset/sequence.cpp index 207eb02b6..7d4f375e8 100644 --- a/src/proc/asset/sequence.cpp +++ b/src/proc/asset/sequence.cpp @@ -47,7 +47,7 @@ namespace asset { getRegistry().append (newSeq); ENSURE (newSeq); - ENSURE (getRegistry().isRegistered(*newSeq)); + ENSURE (getRegistry().isRegistered (*newSeq)); return newSeq; } diff --git a/src/proc/asset/timeline.cpp b/src/proc/asset/timeline.cpp index 1cfdd3466..dbd663b3d 100644 --- a/src/proc/asset/timeline.cpp +++ b/src/proc/asset/timeline.cpp @@ -53,7 +53,7 @@ namespace asset { getRegistry().append (newElement); ENSURE (newElement); - ENSURE (getRegistry().isRegistered(*newElement)); + ENSURE (getRegistry().isRegistered (*newElement)); return newElement; }