Example #1
0
    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);
    }
Example #2
0
        std::shared_ptr<Component>
        get_ptr_postproc_helper(naming::address const& addr,
            naming::id_type const& id)
        {
            if (get_locality() != addr.locality_)
            {
                HPX_THROW_EXCEPTION(bad_parameter,
                    "hpx::get_ptr_postproc<Component, Deleter>",
                    "the given component id does not belong to a local object");
                return std::shared_ptr<Component>();
            }

            if (!traits::component_type_is_compatible<Component>::call(addr))
            {
                HPX_THROW_EXCEPTION(bad_component_type,
                    "hpx::get_ptr_postproc<Component, Deleter>",
                    "requested component type does not match the given component id");
                return std::shared_ptr<Component>();
            }

            Component* p = get_lva<Component>::call(addr.address_);
            std::shared_ptr<Component> ptr(p, Deleter(id));

            ptr->pin();     // the shared_ptr pins the component
            return ptr;
        }
Example #3
0
File: route.cpp Project: hapoo/hpx
    void primary_namespace::route(parcelset::parcel && p)
    { // {{{ route implementation
        util::scoped_timer<std::atomic<std::int64_t> > update(
            counter_data_.route_.time_,
            counter_data_.route_.enabled_
        );
        counter_data_.increment_route_count();

        error_code ec = throws;

        naming::gid_type const& gid = p.destination();
        naming::address& addr = p.addr();
        resolved_type cache_address;

        runtime& rt = get_runtime();

        // resolve destination addresses, we should be able to resolve all of
        // them, otherwise it's an error
        {
            std::unique_lock<mutex_type> l(mutex_);

            // wait for any migration to be completed
            if (naming::detail::is_migratable(gid))
            {
                wait_for_migration_locked(l, gid, ec);
            }

            cache_address = resolve_gid_locked(l, gid, ec);

            if (ec || hpx::util::get<0>(cache_address) == naming::invalid_gid)
            {
                l.unlock();

                HPX_THROWS_IF(ec, no_success,
                    "primary_namespace::route",
                    hpx::util::format(
                        "can't route parcel to unknown gid: {}",
                        gid));

                return;
            }

            // retain don't store in cache flag
            if (!naming::detail::store_in_cache(gid))
            {
                naming::detail::set_dont_store_in_cache(
                    hpx::util::get<0>(cache_address));
            }

            gva const g = hpx::util::get<1>(cache_address).resolve(
                gid, hpx::util::get<0>(cache_address));

            addr.locality_ = g.prefix;
            addr.type_ = g.type;
            addr.address_ = g.lva();
        }

        naming::id_type source = p.source_id();
        // either send the parcel on its way or execute actions locally
        if (addr.locality_ == get_locality())
        {
            // destination is local
            p.schedule_action();
        }
        else
        {
            // destination is remote
            rt.get_parcel_handler().put_parcel(std::move(p));
        }

        if (rt.get_state() < state_pre_shutdown)
        {
            // asynchronously update cache on source locality
            // update remote cache if the id is not flagged otherwise
            naming::gid_type const& id = hpx::util::get<0>(cache_address);
            if (id && naming::detail::store_in_cache(id))
            {
                gva const& g = hpx::util::get<1>(cache_address);
                naming::address addr(g.prefix, g.type, g.lva());

                HPX_ASSERT(naming::is_locality(source));

                hpx::apply<update_agas_cache_action>(
                    source, id, addr, g.count, g.offset);
            }
        }
    } // }}}
Example #4
0
 naming::address get_current_address() const
 {
     return naming::address(get_locality(),
         components::get_component_type<wrapped_type>(),
         boost::uint64_t(static_cast<this_component_type const*>(this)));
 }