示例#1
0
    future<id_type> trigger_migrate_component(
        id_type const& to_migrate, DistPolicy const& policy)
    {
        if (!traits::component_supports_migration<Component>::call())
        {
            return hpx::make_exceptional_future<id_type>(
                HPX_GET_EXCEPTION(invalid_status,
                    "hpx::components::server::trigger_migrate_component",
                    "attempting to migrate an instance of a component which "
                    "does not support migration"));
        }

        if (naming::get_locality_id_from_id(to_migrate) != get_locality_id())
        {
            return hpx::make_exceptional_future<id_type>(
                HPX_GET_EXCEPTION(invalid_status,
                    "hpx::components::server::trigger_migrate_component",
                    "this function has to be executed on the locality "
                    "responsible for managing the address of the given object"));
        }

        auto r = agas::begin_migration(to_migrate);

        // perform actual object migration
        typedef migrate_component_action<Component, DistPolicy> action_type;
        return async<action_type>(r.first, to_migrate, r.second, policy)
            .then(
                [to_migrate](future<id_type> && f) -> id_type
                {
                    agas::end_migration(to_migrate);
                    return f.get();
                });
    }
示例#2
0
 boost::uint32_t get_locality_id(boost::exception_ptr const& e)
 {
     try {
         boost::rethrow_exception(e);
     }
     catch (boost::exception const& be) {
         return get_locality_id(be);
     }
 }
示例#3
0
    HPX_EXPORT std::exception_ptr
    get_exception(Exception const& e, std::string const& func,
        std::string const& file, long line, std::string const& auxinfo)
    {
        if (is_of_lightweight_hpx_category(e))
            return construct_lightweight_exception(e, func, file, line);

        std::int64_t pid = ::getpid();
        std::string back_trace(backtrace());

        std::string state_name("not running");
        std::string hostname;
        hpx::runtime* rt = get_runtime_ptr();
        if (rt)
        {
            state rts_state = rt->get_state();
            state_name = get_runtime_state_name(rts_state);

            if (rts_state >= state_initialized &&
                rts_state < state_stopped)
            {
                std::ostringstream strm;
                strm << get_runtime().here();
                hostname = strm.str();
            }
        }

        // if this is not a HPX thread we do not need to query neither for
        // the shepherd thread nor for the thread id
        error_code ec(lightweight);
        std::uint32_t node = get_locality_id(ec);

        std::size_t shepherd = std::size_t(-1);
        threads::thread_id_type thread_id;
        util::thread_description thread_name;

        threads::thread_self* self = threads::get_self_ptr();
        if (nullptr != self)
        {
            if (threads::threadmanager_is(state_running))
                shepherd = hpx::get_worker_thread_num();

            thread_id = threads::get_self_id();
            thread_name = threads::get_thread_description(thread_id);
        }

        std::string env(get_execution_environment());
        std::string config(configuration_string());

        return construct_exception(e, func, file, line, back_trace, node,
            hostname, pid, shepherd,
            reinterpret_cast<std::size_t>(thread_id.get()),
            util::as_string(thread_name), env, config,
            state_name, auxinfo);
    }
示例#4
0
    future<naming::id_type> trigger_migrate_to_storage_here(
        naming::id_type const& to_migrate,
        naming::id_type const& target_storage)
    {
        if (!Component::supports_migration())
        {
            HPX_THROW_EXCEPTION(invalid_status,
                "hpx::components::server::trigger_migrate_to_storage_here",
                "attempting to migrate an instance of a component which "
                "does not support migration");
            return make_ready_future(naming::invalid_id);
        }

        if (naming::get_locality_id_from_id(to_migrate) != get_locality_id())
        {
            HPX_THROW_EXCEPTION(invalid_status,
                "hpx::components::server::trigger_migrate_to_storage_here",
                "this function has to be executed on the locality responsible "
                "for managing the address of the given object");
            return make_ready_future(naming::invalid_id);
        }

        return agas::begin_migration(to_migrate, target_storage)
            .then(
                [to_migrate, target_storage](
                    future<std::pair<naming::id_type, naming::address> > && f)
                        -> future<naming::id_type>
                {
                    // rethrow errors
                    std::pair<naming::id_type, naming::address> r = f.get();

                    // perform actual object migration
                    typedef server::migrate_to_storage_here_action<Component>
                        action_type;
                    return async<action_type>(r.first, to_migrate, r.second,
                        target_storage);
                })
            .then(
                [to_migrate](future<naming::id_type> && f) -> naming::id_type
                {
                    agas::end_migration(to_migrate).get();
                    return f.get();
                });
    }
示例#5
0
managed_refcnt_checker::~managed_refcnt_checker()
{
    const boost::uint32_t prefix_ = get_locality_id();
    const naming::gid_type this_ = get_base_gid();

    std::ostringstream strm;

    if (!references_.empty())
    {
        strm << ( boost::format("[%1%/%2%]: held references\n")
                  % prefix_ % this_);

        for (naming::id_type const& ref : references_)
        {
            strm << "  " << ref << " "
                 << naming::get_management_type_name(ref.get_management_type())
                 << "\n";
        }

        // Flush garbage collection.
        references_.clear();
        agas::garbage_collect();
    }

    if (naming::invalid_id != target_)
    {
        strm << ( boost::format("[%1%/%2%]: destroying object\n")
                  % prefix_ % this_);

        strm << ( boost::format("[%1%/%2%]: triggering flag %3%\n")
                  % prefix_ % this_ % target_);

        hpx::trigger_lco_event(target_);
    }

    std::string const str = strm.str();

    if (!str.empty())
        cout << str << flush;
}
示例#6
0
    HPX_EXPORT void throw_exception(Exception const& e, std::string const& func,
        std::string const& file, long line)
    {
        boost::int64_t pid_ = ::getpid();
        std::string back_trace(backtrace());

        std::string hostname_ = "";
        if (get_runtime_ptr())
        {
            util::osstream strm;
            strm << get_runtime().here();
            hostname_ = util::osstream_get_string(strm);
        }

        // if this is not a HPX thread we do not need to query neither for
        // the shepherd thread nor for the thread id
        boost::uint32_t node = 0;
        std::size_t shepherd = std::size_t(-1);
        std::size_t thread_id = 0;
        std::string thread_name("");

        threads::thread_self* self = threads::get_self_ptr();
        if (NULL != self)
        {
            if (threads::threadmanager_is(running))
            {
                node = get_locality_id();
                shepherd = threads::threadmanager_base::get_worker_thread_num();
            }

            thread_id = reinterpret_cast<std::size_t>(self->get_thread_id());
            thread_name = threads::get_thread_description(self->get_thread_id());
        }

        rethrow_exception(e, func, file, line, back_trace, node, hostname_,
            pid_, shepherd, thread_id, thread_name);
    }
 std::string get_locality_name()
 {
     std::string basename = get_locality_base_name();
     return basename + '#' + boost::lexical_cast<std::string>(get_locality_id());
 }
示例#8
0
inline void create_thread(
    policies::scheduler_base* scheduler, thread_init_data& data,
    threads::thread_id_type& id,
    thread_state_enum initial_state = pending,
    bool run_now = true, error_code& ec = throws)
{
    // verify parameters
    switch (initial_state) {
    case pending:
    case pending_do_not_schedule:
    case suspended:
        break;

    default:
    {
        std::ostringstream strm;
        strm << "invalid initial state: "
             << get_thread_state_name(initial_state);
        HPX_THROWS_IF(ec, bad_parameter,
                      "threads::detail::create_thread",
                      strm.str());
        return;
    }
    }

#ifdef HPX_HAVE_THREAD_DESCRIPTION
    if (!data.description)
    {
        HPX_THROWS_IF(ec, bad_parameter,
                      "threads::detail::create_thread", "description is nullptr");
        return;
    }
#endif

    thread_self* self = get_self_ptr();

#ifdef HPX_HAVE_THREAD_PARENT_REFERENCE
    if (nullptr == data.parent_id) {
        if (self)
        {
            data.parent_id = threads::get_self_id().get();
            data.parent_phase = self->get_thread_phase();
        }
    }
    if (0 == data.parent_locality_id)
        data.parent_locality_id = get_locality_id();
#endif

    if (nullptr == data.scheduler_base)
        data.scheduler_base = scheduler;

    // Pass critical priority from parent to child.
    if (self)
    {
        if (thread_priority_critical == threads::get_self_id()->get_priority())
            data.priority = thread_priority_critical;
    }

    // create the new thread
    std::size_t num_thread = data.num_os_thread;
    scheduler->create_thread(data, &id, initial_state, run_now, ec, num_thread);

    LTM_(info) << "register_thread(" << id << "): initial_state("
               << get_thread_state_name(initial_state) << "), "
               << "run_now(" << (run_now ? "true" : "false")
#ifdef HPX_HAVE_THREAD_DESCRIPTION
               << "), description(" << data.description
#endif
               << ")";

    // potentially wake up waiting thread
    scheduler->do_some_work(num_thread);
}
示例#9
0
    inline threads::thread_id_type create_thread(
        policies::scheduler_base* scheduler,
        thread_init_data& data, thread_state_enum initial_state = pending,
        bool run_now = true, error_code& ec = throws)
    {
        // verify parameters
        switch (initial_state) {
        case pending:
        case suspended:
            break;

        default:
            {
                hpx::util::osstream strm;
                strm << "invalid initial state: "
                     << get_thread_state_name(initial_state);
                HPX_THROWS_IF(ec, bad_parameter,
                    "threads::detail::create_thread",
                    hpx::util::osstream_get_string(strm));
                return invalid_thread_id;
            }
        }

#if HPX_THREAD_MAINTAIN_DESCRIPTION
        if (0 == data.description)
        {
            HPX_THROWS_IF(ec, bad_parameter,
                "threads::detail::create_thread", "description is NULL");
            return invalid_thread_id;
        }
#endif

#if HPX_THREAD_MAINTAIN_PARENT_REFERENCE
        if (0 == data.parent_id) {
            thread_self* self = get_self_ptr();
            if (self)
            {
                data.parent_id = threads::get_self_id().get();
                data.parent_phase = self->get_thread_phase();
            }
        }
        if (0 == data.parent_locality_id)
            data.parent_locality_id = get_locality_id();
#endif

        if (0 == data.scheduler_base)
            data.scheduler_base = scheduler;

        // create the new thread
        thread_id_type newid = scheduler->create_thread(
            data, initial_state, run_now, ec, data.num_os_thread);

        LTM_(info) << "register_thread(" << newid << "): initial_state("
                   << get_thread_state_name(initial_state) << "), "
                   << "run_now(" << (run_now ? "true" : "false")
#if HPX_THREAD_MAINTAIN_DESCRIPTION
                   << "), description(" << data.description
#endif
                   << ")";

        return newid;
    }
示例#10
0
 boost::uint32_t get_locality_id(hpx::exception const& e)
 {
     return get_locality_id(dynamic_cast<boost::exception const&>(e));
 }