void default_actor_addressing::erase(process_information& inf, actor_id aid) {
    CPPA_LOGMF(CPPA_TRACE, self, CPPA_TARG(inf, to_string) << ", " << CPPA_ARG(aid));
    auto i = m_proxies.find(inf);
    if (i != m_proxies.end()) {
        i->second.erase(aid);
    }
}
示例#2
0
void actor_registry::await_running_count_equal(size_t expected) {
    CPPA_LOG_TRACE(CPPA_ARG(expected));
    std::unique_lock<std::mutex> guard(m_running_mtx);
    while (m_running.load() != expected) {
        m_running_cv.wait(guard);
    }
}
示例#3
0
actor_registry::value_type actor_registry::get_entry(actor_id key) const {
    shared_guard guard(m_instances_mtx);
    auto i = m_entries.find(key);
    if (i != m_entries.end()) {
        return i->second;
    }
    CPPA_LOG_DEBUG("no cache entry found for " << CPPA_ARG(key));
    return {nullptr, exit_reason::not_exited};
}
actor_ptr default_actor_addressing::get_or_put(const process_information& inf,
        actor_id aid) {
    auto result = get(inf, aid);
    if (result == nullptr) {
        CPPA_LOGMF(CPPA_INFO, self, "created new proxy instance; "
                   << CPPA_TARG(inf, to_string) << ", " << CPPA_ARG(aid));
        auto ptr = make_counted<default_actor_proxy>(aid, new process_information(inf), m_parent);
        put(inf, aid, ptr);
        result = ptr;
    }
    return result;
}
actor_ptr default_actor_addressing::get(const process_information& inf,
                                        actor_id aid) {
    auto& submap = m_proxies[inf];
    auto i = submap.find(aid);
    if (i != submap.end()) {
        auto result = i->second.promote();
        CPPA_LOGMF_IF(!result, CPPA_INFO, self, "proxy instance expired; "
                      << CPPA_TARG(inf, to_string) << ", "<< CPPA_ARG(aid));
        if (!result) submap.erase(i);
        return result;
    }
    return nullptr;
}
示例#6
0
void abstract_actor::cleanup(std::uint32_t reason) {
    // log as 'actor'
    CPPA_LOGM_TRACE("cppa::actor", CPPA_ARG(m_id) << ", " << CPPA_ARG(reason)
                    << ", " << CPPA_ARG(m_is_proxy));
    CPPA_REQUIRE(reason != exit_reason::not_exited);
    // move everyhting out of the critical section before processing it
    decltype(m_links) mlinks;
    decltype(m_attachables) mattachables;
    { // lifetime scope of guard
        guard_type guard{m_mtx};
        if (m_exit_reason != exit_reason::not_exited) {
            // already exited
            return;
        }
        m_exit_reason = reason;
        mlinks = std::move(m_links);
        mattachables = std::move(m_attachables);
        // make sure lists are empty
        m_links.clear();
        m_attachables.clear();
    }
    CPPA_LOGC_INFO_IF(not is_proxy(), "cppa::actor", __func__,
                      "actor with ID " << m_id << " had " << mlinks.size()
                      << " links and " << mattachables.size()
                      << " attached functors; exit reason = " << reason
                      << ", class = " << detail::demangle(typeid(*this)));
    // send exit messages
    auto msg = make_any_tuple(exit_msg{address(), reason});
    CPPA_LOGM_DEBUG("cppa::actor", "send EXIT to " << mlinks.size() << " links");
    for (auto& aptr : mlinks) {
        aptr->enqueue({address(), aptr, message_id{}.with_high_priority()},
                      msg, m_host);
    }
    CPPA_LOGM_DEBUG("cppa::actor", "run " << mattachables.size()
                                   << " attachables");
    for (attachable_ptr& ptr : mattachables) {
        ptr->actor_exited(reason);
    }
}
示例#7
0
 void launch(Actor* self, execution_unit*) {
     CPPA_REQUIRE(self != nullptr);
     CPPA_PUSH_AID(self->id());
     CPPA_LOG_TRACE(CPPA_ARG(self));
     intrusive_ptr<Actor> mself{self};
     self->attach_to_scheduler();
     std::thread([=] {
         CPPA_PUSH_AID(mself->id());
         CPPA_LOG_TRACE("");
         detail::cs_thread fself;
         for (;;) {
             if (mself->resume(&fself, nullptr) == resumable::done) {
                 return;
             }
             // await new data before resuming actor
             await_data(mself.get());
             CPPA_REQUIRE(self->mailbox().blocked() == false);
         }
         self->detach_from_scheduler();
     }).detach();
 }
void context_switching_resume::trampoline(void* this_ptr) {
    CPPA_LOGF_TRACE(CPPA_ARG(this_ptr));
    auto self = reinterpret_cast<blocking_actor*>(this_ptr);
    auto shut_actor_down = [self](std::uint32_t reason) {
        if (self->planned_exit_reason() == exit_reason::not_exited) {
            self->planned_exit_reason(reason);
        }
        self->on_exit();
        self->cleanup(self->planned_exit_reason());
    };
    try {
        self->act();
        shut_actor_down(exit_reason::normal);
    }
    catch (actor_exited& e) {
        shut_actor_down(e.reason());
    }
    catch (...) {
        shut_actor_down(exit_reason::unhandled_exception);
    }
    std::atomic_thread_fence(std::memory_order_seq_cst);
    CPPA_LOGF_DEBUG("done, yield() back to execution unit");;
    detail::yield(detail::yield_state::done);
}
void middleman_event_handler::erase_later(continuable* ptr, event_bitmask e) {
    CPPA_LOG_TRACE(CPPA_ARG(ptr) << ", e = " << eb2str(e));
    alteration(ptr, e, fd_meta_event::erase);
}
void middleman_event_handler::add_later(continuable* ptr, event_bitmask e) {
    CPPA_LOG_TRACE(CPPA_ARG(ptr) << ", "
                   << CPPA_TARG(e, eb2str)
                   << ", socket = " << ptr->read_handle());
    alteration(ptr, e, fd_meta_event::add);
}
示例#11
0
void local_actor::cleanup(std::uint32_t reason) {
    CPPA_LOG_TRACE(CPPA_ARG(reason));
    m_subscriptions.clear();
    super::cleanup(reason);
}