void destroy(naming::gid_type const& gid, naming::address const& addr) { // make sure this component is located here if (get_locality() != addr.locality_) { // This component might have been migrated, find out where it is // and instruct that locality to delete it. destroy_component(gid, addr); return; } // make sure it's the correct component type components::component_type type = components::get_component_type<typename Component::wrapped_type>(); if (!types_are_compatible(type, addr.type_)) { // FIXME: should the component be re-bound ? std::ostringstream strm; strm << "global id " << gid << " is not bound to a component " "instance of type: " << get_component_type_name(type) << " (it is bound to a " << get_component_type_name(addr.type_) << ")"; HPX_THROW_EXCEPTION(hpx::unknown_component_address, "destroy<Component>", strm.str()); return; } --instance_count(type); // delete the local instances Component *c = reinterpret_cast<Component*>(addr.address_); c->finalize(); c->~Component(); component_heap<Component>().free(c, 1); }
std::vector<naming::gid_type> bulk_create(std::size_t count, Ts&&...ts) { component_type type = get_component_type<typename Component::wrapped_type>(); std::vector<naming::gid_type> gids; if(!enabled(type)) { HPX_THROW_EXCEPTION(bad_request, "components::server::bulk_create", "the component is disabled for this locality (" + get_component_type_name(type) + ")"); return gids; } gids.reserve(count); Component *storage = static_cast<Component*>(component_heap<Component>().alloc(count)); Component *storage_it = storage; std::size_t succeeded = 0; try { // Call constructors and try to get the GID... for (std::size_t i = 0; i != count; ++i, ++storage_it) { Component* c = nullptr; c = new(storage_it) Component(std::forward<Ts>(ts)...); naming::gid_type gid = c->get_base_gid(); if (!gid) { c->finalize(); c->~Component(); HPX_THROW_EXCEPTION(hpx::unknown_component_address, "bulk_create<Component>", "can't assign global id"); } gids.push_back(std::move(gid)); ++instance_count(type); ++succeeded; } } catch(...) { // If an exception wsa thrown, roll back storage_it = storage; for (std::size_t i = 0; i != succeeded; ++i, ++storage_it) { storage_it->finalize(); storage_it->~Component(); --instance_count(type); } component_heap<Component>().free(storage, count); throw; } return gids; }
naming::gid_type create_migrated(naming::gid_type const& gid, void** p, Ts&&...ts) { component_type type = get_component_type<typename Component::wrapped_type>(); if(!enabled(type)) { HPX_THROW_EXCEPTION(bad_request, "components::server::create_migrated", "the component is disabled for this locality (" + get_component_type_name(type) + ")"); return naming::invalid_gid; } void *storage = component_heap<Component>().alloc(1); Component* c = nullptr; try { c = new(storage) Component(std::forward<Ts>(ts)...); } catch(...) { component_heap<Component>().free(c, 1); throw; } naming::gid_type assigned_gid = c->get_base_gid(gid); if (assigned_gid && assigned_gid == gid) { // everything is ok, return the new id if (p != nullptr) *p = c; // return the raw address as well ++instance_count(type); return gid; } c->finalize(); c->~Component(); component_heap<Component>().free(c, 1); std::ostringstream strm; strm << "global id " << gid << " is already bound to a different component instance"; HPX_THROW_EXCEPTION(hpx::duplicate_component_address, "create<Component>(naming::gid_type, ctor)", strm.str()); return naming::invalid_gid; }
naming::gid_type create(Ts&&...ts) { component_type type = get_component_type<typename Component::wrapped_type>(); if(!enabled(type)) { HPX_THROW_EXCEPTION(bad_request, "components::server::::create", "the component is disabled for this locality (" + get_component_type_name(type) + ")"); return naming::invalid_gid; } void *storage = component_heap<Component>().alloc(1); Component* c = nullptr; try { c = new(storage) Component(std::forward<Ts>(ts)...); } catch(...) { component_heap<Component>().free(c, 1); throw; } naming::gid_type gid = c->get_base_gid(); if (!gid) { c->finalize(); c->~Component(); component_heap<Component>().free(c, 1); HPX_THROW_EXCEPTION(hpx::unknown_component_address, "create<Component>", "can't assign global id"); } ++instance_count(type); return gid; }
wrapper_heap_list(component_type type) : base_type(get_component_type_name(type)), type_(type) {}