Beispiel #1
0
void
_lthread_poller_set_fd_ready(struct lthread *lt, int fd, enum lthread_event e,
    int is_eof)
{
    /* 
     * not all scheduled fds in the poller are guaranteed to have triggered,
     * deschedule them all and cancel events in poller so they don't trigger later.
     */
    int i;
    if (lt->ready_fds == 0) {
        for (i = 0; i < lt->nfds; i++)
            if (lt->pollfds[i].events & POLLIN) {
                _lthread_poller_ev_clear_rd(lt->pollfds[i].fd);
                _lthread_desched_event(lt->pollfds[i].fd, LT_EV_READ);
            } else if (lt->pollfds[i].events & POLLOUT) {
                _lthread_poller_ev_clear_wr(lt->pollfds[i].fd);
                _lthread_desched_event(lt->pollfds[i].fd, LT_EV_WRITE);
            }
    }


    lt->pollfds[lt->ready_fds].fd = fd;
    if (e == LT_EV_WRITE)
        lt->pollfds[lt->ready_fds].events = POLLOUT;
    else
        lt->pollfds[lt->ready_fds].events = POLLIN;

    if (is_eof)
        lt->pollfds[lt->ready_fds].events |= POLLHUP;

    lt->ready_fds++;
}
Beispiel #2
0
int
lthread_close(int fd)
{
    struct lthread *lt = NULL;

    /* wake up the lthreads waiting on this fd and notify them of close */
    lt = _lthread_desched_event(fd, LT_EV_READ);
    if (lt) {
        TAILQ_INSERT_TAIL(&lthread_get_sched()->ready, lt, ready_next);
        lt->state |= BIT(LT_ST_FDEOF);
    }

    lt = _lthread_desched_event(fd, LT_EV_WRITE);
    if (lt) {
        TAILQ_INSERT_TAIL(&lthread_get_sched()->ready, lt, ready_next);
        lt->state |= BIT(LT_ST_FDEOF);
    }

    /* clear the eof bit of the calling lthread */
    lt = lthread_get_sched()->current_lthread;
    if (lt->state & BIT(LT_ST_FDEOF)) {
        lt->state &= CLEARBIT(LT_ST_FDEOF);
    }

    /* closing fd removes its registered events from poller */
    return (close(fd));
}
Beispiel #3
0
int
lthread_close(int fd)
{
    LTHREAD_SOCKET_CHECK_SCHED(close(fd));
    struct lthread *lt = NULL;

    /* wake up the lthreads waiting on this fd and notify them of close */
    lt = _lthread_desched_event(fd, LT_EV_READ);
    if (lt) {
        TAILQ_INSERT_TAIL(&lthread_get_sched()->ready, lt, ready_next);
        lt->state |= BIT(LT_ST_FDEOF);
    }

    lt = _lthread_desched_event(fd, LT_EV_WRITE);
    if (lt) {
        TAILQ_INSERT_TAIL(&lthread_get_sched()->ready, lt, ready_next);
        lt->state |= BIT(LT_ST_FDEOF);
    }

    /* closing fd removes its registered events from poller */ 
    return (close(fd));
}