Exemple #1
0
void Sched::action(Listener* obj, int e) { __logc;
    int idx;
    unordered_set<Task*>::iterator it;
    Task *t = dynamic_cast<Task*>(obj);
    logger.print("obj = %p, e = %x", obj, e);
    if (t == NULL)
        logger.raise("dynamic_cast<Task*>");
    if (e & E_FINISHED) {
        if ((it = running.find(t)) == running.end())
            logger.raise("running not found");
        idx = std::find(assoc, assoc + P, t) - assoc;
        if (idx == P)
            logger.raise("assoc not found");
        running.erase(it);
        t->detach();
        if (pending.empty()) {
            assoc[idx] = NULL;
            busy[idx] = false;
        } else {
            it = pending.begin();
            (*it)->attach(procs[idx]);
            assoc[idx] = *it;
            pending.erase(it);
            running.insert(assoc[idx]);
        }
    } else if (e & E_ERROR) {
        idx = std::find(assoc, assoc + P, t) - assoc;
        if (idx == P)
            throw "Sched assoc not found";
        t->detach();
        delete procs[idx];
        procs[idx] = new Subprocess(sorting.c_str());
        t->attach(procs[idx]);
    } else {
        throw "Sched received unknown message";
    }
}