Hi all,

I get a question when reading the source code in
/noxcore/src/lib/event-dispatcher.cc

bool
Event_dispatcher::poll()
{
    size_t max = p->queue.size();
    unsigned int serial = ++p->serial;
    for (size_t i = 0; i < max; ++i) {
        std::auto_ptr<Event> event(p->queue.pop_front().release());
        dispatch(*event);

        if (serial != p->serial) {
            /* dispatch(*event) blocked and Event_dispatcher::poll() was
             * eventually re-entered in another thread.  That other call
             * already dispatched our events, so we are done. */
            break;
        }
    }
    return max > 0;
}

What does the "dispatch(*event) blocked" mean in the comment here?
In what situation the Event_dispatcher::dispatch() may block?
Please see the mark [?] below:

void
Event_dispatcher::dispatch(const Event& e)
{
    const Event_name& name = e.get_name();
    if (p->table.find(name) != p->table.end()) {
        BOOST_FOREACH (Signal::value_type& i, p->table[name]) {
            try {

                // [?] is it possible an event handler may block here?
                // e.g. co_block() is called at the application level. I
guess not...
                if (i.second(e) == STOP) {

                    break;
                }
            } catch (const std::exception& e) {
                lg.err("Event processing leaked an exception: %s",
e.what());
                break;
            }
        }
    }
}


Deng
_______________________________________________
nox-dev mailing list
[email protected]
http://noxrepo.org/mailman/listinfo/nox-dev_noxrepo.org

Reply via email to