Mend clean up for Shared Clients

nix
Owen Green 6 years ago
parent 9542b9be78
commit ce22e867db

@ -737,6 +737,7 @@ struct LifetimePolicy<Client, Wrapper,std::false_type, std::true_type>
using SharedType = typename GetSharedType<Client>::type; using SharedType = typename GetSharedType<Client>::type;
using ClientPointer = typename SharedType::ClientPointer; using ClientPointer = typename SharedType::ClientPointer;
using ParamType = typename Client::ParamSetType;
static void constructClass(Unit* unit) static void constructClass(Unit* unit)
{ {
@ -748,16 +749,18 @@ struct LifetimePolicy<Client, Wrapper,std::false_type, std::true_type>
auto& name = params.template get<0>(); auto& name = params.template get<0>();
auto client = Client{params}; mParamsRegistry.emplace(name, ParamType{params});
auto clientRef = SharedType::lookup(name); mClientRegistry.emplace(name, Client{params});
auto pos = mRegistry.find(clientRef);
if(pos == mRegistry.end()) mRegistry.emplace(clientRef);
auto client = Client{params};
new (static_cast<Wrapper*>(unit)) Wrapper(std::move(controlsReader),std::move(client),std::move(params)); new (static_cast<Wrapper*>(unit)) Wrapper(std::move(controlsReader),std::move(client),std::move(params));
} }
static void destroyClass(Unit* unit) { static_cast<Wrapper*>(unit)->~Wrapper(); } static void destroyClass(Unit* unit) {
std::cout << "Regsitry size :" << mClientRegistry.size() << '\n';
static_cast<Wrapper*>(unit)->~Wrapper();
}
static void setup(InterfaceTable* ft, const char* name) static void setup(InterfaceTable* ft, const char* name)
{ {
@ -769,10 +772,9 @@ struct LifetimePolicy<Client, Wrapper,std::false_type, std::true_type>
[](World*,void*,sc_msg_iter* args, void* /*replyAddr*/) [](World*,void*,sc_msg_iter* args, void* /*replyAddr*/)
{ {
auto objectName = std::string(args->gets()); auto objectName = std::string(args->gets());
auto clientRef = SharedType::lookup(objectName); mClientRegistry.erase(objectName);
auto pos = mRegistry.find(clientRef); mParamsRegistry.erase(objectName);
if(pos != mRegistry.end()) mRegistry.erase(clientRef); }, &mClientRegistry);
}, &mRegistry);
} }
private: private:
@ -783,14 +785,17 @@ private:
return SharedType::lookup(name); return SharedType::lookup(name);
} }
static std::unordered_set<ClientPointer> mRegistry; static std::unordered_map<std::string,Client> mClientRegistry;
static std::unordered_map<std::string,ParamType> mParamsRegistry;
}; };
template<typename Client, typename Wrapper> template<typename Client, typename Wrapper>
std::unordered_set<typename LifetimePolicy<Client, Wrapper, std::false_type, std::true_type>::ClientPointer> std::unordered_map<std::string, Client>
LifetimePolicy<Client, Wrapper, std::false_type, std::true_type>::mRegistry{}; LifetimePolicy<Client, Wrapper, std::false_type, std::true_type>::mClientRegistry{};
template<typename Client, typename Wrapper>
std::unordered_map<std::string, typename LifetimePolicy<Client, Wrapper, std::false_type, std::true_type>::ParamType>
LifetimePolicy<Client, Wrapper, std::false_type, std::true_type>::mParamsRegistry{};
//// Template Specialisations for NRT/RT //// Template Specialisations for NRT/RT
template <typename Client, typename Wrapper, typename NRT, typename RT> template <typename Client, typename Wrapper, typename NRT, typename RT>

Loading…
Cancel
Save