Ejemplo n.º 1
0
void TaskGraph::taskStateChanged(ptr<Task> t, bool done, reason r)
{
    assert(allTasks.find(t) != allTasks.end());
    if (!done) {
        if (r != DATA_NEEDED) {
            Task::setIsDone(false, 0, r);

            // if the result of t is needed again but has not changed, the
            // tasks that depend on this result need not be reexecuted.
            // Otherwise we notify these successor tasks that one of their
            // dependencies has changed, and that they must be reexecuted:
            TaskIterator i = getInverseDependencies(t);
            while (i.hasNext()) {
                ptr<Task> s = i.next();
                s->setIsDone(false, 0, DEPENDENCY_CHANGED);
            }
        }
    } else {
        // updates the predecessor completion date of the successors of t
        completionDateChanged(t, t->getCompletionDate());

        // if a subtask of this task graph is now completed, the task graph
        // itself may become completed (it can of course not become uncompleted).
        TaskIterator i = getAllTasks();
        while (i.hasNext()) {
            if (!i.next()->isDone()) {
                return;
            }
        }
        Task::setIsDone(true, getCompletionDate());
    }
}
Ejemplo n.º 2
0
void TaskGraph::completionDateChanged(ptr<Task> t, unsigned int date)
{
    completionDate = max(completionDate, date);
    TaskIterator i = getInverseDependencies(t);
    if (i.hasNext()) {
        // if t has successors,
        // updates the predecessor completion date of the successors of t
        while (i.hasNext()) {
            ptr<Task> s = i.next();
            s->setPredecessorsCompletionDate(date);
        }
    } else {
        // if t does not have predecessors, notifies the listeners of
        // this taskgraph that its completion date has changed
        for (unsigned int i = 0; i < listeners.size(); ++i) {
            listeners[i]->completionDateChanged(this, date);
        }
    }
}