void middleman_event_handler::alteration(continuable* ptr,
                                         event_bitmask e,
                                         fd_meta_event etype) {
    native_socket_type fd;
    switch (e) {
        case event::read:
            fd = ptr->read_handle();
            break;
        case event::write: {
            fd = ptr->write_handle();
            break;
        }
        case event::both: {
            fd = ptr->read_handle();
            auto wrfd = ptr->write_handle();
            if (fd != wrfd) {
                CPPA_LOG_DEBUG("read_handle != write_handle, split "
                               "into two function calls");
                // split into two function calls
                e = event::read;
                alteration(ptr, event::write, etype);
            }
            break;
        }
        default:
            CPPA_CRITICAL("invalid bitmask");
            return;
    }
    m_alterations.emplace_back(fd_meta_info(fd, ptr, e), etype);
}
Exemplo n.º 2
0
 bool synchronized_enqueue(Mutex& mtx, CondVar& cv, pointer new_element) {
     switch (enqueue(new_element)) {
         case enqueue_result::unblocked_reader: {
             std::unique_lock<Mutex> guard(mtx);
             cv.notify_one();
             return true;
         }
         case enqueue_result::success:
             // enqueued message to a running actor's mailbox
             return true;
         case enqueue_result::queue_closed:
             // actor no longer alive
             return false;
     }
     // should be unreachable
     CPPA_CRITICAL("invalid result of enqueue()");
 }
Exemplo n.º 3
0
resume_result event_based_actor::resume(util::fiber*) {
    scoped_self_setter sss{this};
    auto done_cb = [&]() {
        m_state.store(abstract_scheduled_actor::done);
        m_bhvr_stack.clear();
        on_exit();
    };
    try {
        detail::recursive_queue_node* e;
        for (;;) {
            e = m_mailbox.try_pop();
            if (!e) {
                m_state.store(abstract_scheduled_actor::about_to_block);
                if (m_mailbox.can_fetch_more() == false) {
                    switch (compare_exchange_state(
                                abstract_scheduled_actor::about_to_block,
                                abstract_scheduled_actor::blocked)) {
                        case abstract_scheduled_actor::ready: {
                            break;
                        }
                        case abstract_scheduled_actor::blocked: {
                            return resume_result::actor_blocked;
                        }
                        default: CPPA_CRITICAL("illegal actor state");
                    };
                }
            }
            else if (m_bhvr_stack.invoke(m_policy, this, e)) {
                if (m_bhvr_stack.empty()) {
                    done_cb();
                    return resume_result::actor_done;
                }
            }
        }
    }
    catch (actor_exited& what) { cleanup(what.reason()); }
    catch (...)                { cleanup(exit_reason::unhandled_exception); }
    done_cb();
    return resume_result::actor_done;
}
Exemplo n.º 4
0
std::pair<native_socket_type, native_socket_type> create_pipe() {
    native_socket_type pipefds[2];
    if (pipe(pipefds) != 0) { CPPA_CRITICAL("cannot create pipe"); }
    return {pipefds[0], pipefds[1]};
}