Ejemplo n.º 1
0
int _wait(void *socket, int fd, int rw)
{
    startfdtask();
    check(socket != NULL || fd >= 0, "Attempt to wait on a dead socket/fd: %p or %d", socket, fd);

    int max = 0;
    int hot_add = SuperPoll_active_hot(POLL) < SuperPoll_max_hot(POLL);
    int was_registered = 0;

    if(socket != NULL) {
        taskstate(rw == 'r' ? "read handler" : "write handler");
    } else {
        was_registered = Register_fd_exists(fd) != NULL;
        taskstate(rw == 'r' ? "read fd" : "write fd");
    }

    max = SuperPoll_add(POLL, (void *)taskrunning, socket, fd, rw, hot_add);
    check(max != -1, "Error adding fd: %d or socket: %p to task wait list.", fd, socket);

    taskswitch();

    if(task_was_signaled()) {
        debug("GOT SIGNAL %d AFTER WAIT", taskrunning->signal);
        SuperPoll_del(POLL, socket, fd, hot_add);
        return -1;
    } if(was_registered && Register_fd_exists(fd) == NULL) {
        debug("Socket %d was closed after a wait.", fd);
        return -1;
    } else {
        return 0;
    }

error:
    return -1;
}
Ejemplo n.º 2
0
static inline void fdtask_shutdown()
{
    int i = 0;

    for(i = 0; i < SuperPoll_active_hot(POLL); i++) {
        SuperPoll_compact_down(POLL, i);
    }

    // move all our sleeping tasks over to the main runqueue
    Task *t = NULL;
    while((t = sleeping.head)){
        deltask(&sleeping, t);
        tasksignal(t, task_was_signaled());
    }
}
Ejemplo n.º 3
0
int tasknuke(int id)
{
    int i = 0;
    Task *target = NULL;

    for(i = 0; i < SuperPoll_active_hot(POLL); i++) {
        target = (Task *)SuperPoll_data(POLL, i);

        if(target && target->id == id) {
            SuperPoll_compact_down(POLL, i);
            return 0;
        }
    }

    return -1;
}
Ejemplo n.º 4
0
void
fdtask(void *v)
{
    int i, ms;
    PollResult result;
    int rc = 0;
    
    rc = PollResult_init(POLL, &result);
    check(rc == 0, "Failed to initialize the poll result.");

    tasksystem();
    taskname("fdtask");

    for(;;){
        /* let everyone else run */
        while(taskyield() > 0)
            ;
        /* we're the only one runnable - poll for i/o */
        errno = 0;
        taskstate("poll");

        ms = next_task_sleeptime(500);

        if(SIGNALED) {
            for(i = 0; i < SuperPoll_active_hot(POLL); i++) {
                Task *target = (Task *)SuperPoll_data(POLL, i);
                if(target) taskready(target);
                SuperPoll_compact_down(POLL, i);
            }
        } else {
            rc = SuperPoll_poll(POLL, &result, ms);
            check(rc != -1, "SuperPoll failure, aborting.");

            for(i = 0; i < rc; i++) {
                taskready(result.hits[i].data); 
            }
        }

        wake_sleepers();
    }

    PollResult_clean(&result);
    taskexit(0);

error:
    taskexitall(1);
}
Ejemplo n.º 5
0
int _wait(void *socket, int fd, int rw)
{
    startfdtask();

    int max = 0;
    int hot_add = SuperPoll_active_hot(POLL) < SuperPoll_max_hot(POLL);
    
    taskstate(rw == 'r' ? "read wait" : "write wait");

    max = SuperPoll_add(POLL, (void *)taskrunning, socket, fd, rw, hot_add);
    check(max != -1, "Error adding fd %d to task wait list.", fd);

    taskswitch();
    return 0;

error:
    taskswitch();
    return -1;
}