From ce22e867dbc477a621f2afff78b6a171bbb13b6f Mon Sep 17 00:00:00 2001 From: Owen Green Date: Wed, 10 Jun 2020 15:12:22 +0100 Subject: [PATCH] Mend clean up for Shared Clients --- include/FluidSCWrapper.hpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/include/FluidSCWrapper.hpp b/include/FluidSCWrapper.hpp index 80d88ff..34b80eb 100644 --- a/include/FluidSCWrapper.hpp +++ b/include/FluidSCWrapper.hpp @@ -737,6 +737,7 @@ struct LifetimePolicy using SharedType = typename GetSharedType::type; using ClientPointer = typename SharedType::ClientPointer; + using ParamType = typename Client::ParamSetType; static void constructClass(Unit* unit) { @@ -747,17 +748,19 @@ struct LifetimePolicy Wrapper::setParams(unit, params,controlsReader,true); auto& name = params.template get<0>(); - + + mParamsRegistry.emplace(name, ParamType{params}); + mClientRegistry.emplace(name, Client{params}); + auto client = Client{params}; - auto clientRef = SharedType::lookup(name); - - auto pos = mRegistry.find(clientRef); - if(pos == mRegistry.end()) mRegistry.emplace(clientRef); - new (static_cast(unit)) Wrapper(std::move(controlsReader),std::move(client),std::move(params)); } - static void destroyClass(Unit* unit) { static_cast(unit)->~Wrapper(); } + static void destroyClass(Unit* unit) { + std::cout << "Regsitry size :" << mClientRegistry.size() << '\n'; + static_cast(unit)->~Wrapper(); + + } static void setup(InterfaceTable* ft, const char* name) { @@ -769,10 +772,9 @@ struct LifetimePolicy [](World*,void*,sc_msg_iter* args, void* /*replyAddr*/) { auto objectName = std::string(args->gets()); - auto clientRef = SharedType::lookup(objectName); - auto pos = mRegistry.find(clientRef); - if(pos != mRegistry.end()) mRegistry.erase(clientRef); - }, &mRegistry); + mClientRegistry.erase(objectName); + mParamsRegistry.erase(objectName); + }, &mClientRegistry); } private: @@ -783,14 +785,17 @@ private: return SharedType::lookup(name); } - static std::unordered_set mRegistry; + static std::unordered_map mClientRegistry; + static std::unordered_map mParamsRegistry; }; template -std::unordered_set::ClientPointer> - LifetimePolicy::mRegistry{}; - +std::unordered_map + LifetimePolicy::mClientRegistry{}; +template +std::unordered_map::ParamType> + LifetimePolicy::mParamsRegistry{}; //// Template Specialisations for NRT/RT template