示例#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());
    }
}
示例#2
0
void TaskGraph::setPredecessorsCompletionDate(unsigned int t)
{
    TaskIterator i = getFirstTasks();
    while (i.hasNext()) {
        i.next()->setPredecessorsCompletionDate(t);
    }
}
示例#3
0
TaskGraph::~TaskGraph()
{
    TaskIterator i = getAllTasks();
    while (i.hasNext()) {
        i.next()->removeListener(this);
    }
}
示例#4
0
void TaskGraph::setIsDone(bool done, unsigned int t, reason r)
{
    Task::setIsDone(done, t, r);
    if (!done) { // calls sub tasks recursively only if task must be reexecuted
        // if a dependency of this task graph has changed, then all sub tasks
        // must be reexecuted; otherwise, if the data produced by this graph
        // is needed again then, a priori, only the sub tasks without successors
        // must be reexecuted (these sub tasks may need other sub tasks to be
        // reexecuted if they need their data; in this case they can change
        // their execution state recursively in their own setIsDone method).
        TaskIterator i = r == DEPENDENCY_CHANGED ? getAllTasks() : getLastTasks();
        while (i.hasNext()) {
            i.next()->setIsDone(done, t, r);
        }
    }
}
示例#5
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);
        }
    }
}