Пример #1
0
static int join(Ejs *ejs, EjsObj *workers, int timeout)
{
    MprTicks    mark;
    int         result, remaining;

    mprTrace(5, "Worker.join: joining %d", ejs->joining);
    
    mark = mprGetTicks();
    remaining = timeout;
    do {
        ejs->joining = !reapJoins(ejs, workers);
        if (!ejs->joining) {
            break;
        }
        if (mprShouldAbortRequests()) {
            ejsThrowStateError(ejs, "Program instructed to exit");
            break;
        }
        mprWaitForEvent(ejs->dispatcher, remaining);
        remaining = (int) mprGetRemainingTicks(mark, timeout);
    } while (remaining > 0 && !ejs->exception);

    if (ejs->exception) {
        return 0;
    }
    result = (ejs->joining) ? MPR_ERR_TIMEOUT: 0;
    ejs->joining = 0;
    mprTrace(7, "Worker.join: result %d", result);
    return result;
}
Пример #2
0
static int join(Ejs *ejs, EjsVar *workers, int timeout)
{
    MprTime     mark, remaining;
    int         result, count, total;

    mark = mprGetTime(ejs);
    ejs->joining = 1;

    do {
        /*
         *  Must process all pending messages
         */
        total = 0;
        while ((count = mprServiceEvents(ejs->dispatcher, 0, MPR_SERVICE_EVENTS)) > 0) { 
            total += count;
        }
        ejs->joining = !reapJoins(ejs, workers);
        if (total == 0 && ejs->joining) {
            mprWaitForCond(ejs->dispatcher->cond, timeout);
        }
        remaining = mprGetRemainingTime(ejs, mark, timeout);
    } while (ejs->joining && remaining > 0 && !ejs->exception);

    if (ejs->exception) {
        return 0;
    }
    result = (ejs->joining) ? MPR_ERR_TIMEOUT: 0;
    ejs->joining = 0;
    return result;
}