void CRUTopologicalDGIterator::UpdateIterator(CRUTaskList &taskList)
{
	TaskLink link = {NULL, 0};

	DSListPosition pos = taskList.GetHeadPosition();
	while (NULL != pos)
	{
		CRUTask *pTask = taskList.GetNext(pos);

		// Locate the link in the link map
		BOOL ret = allTasksLinkMap_.Lookup(pTask->GetId(), link);
		RUASSERT(TRUE == ret);

		// One reference less to the task
		link.refCount_--;

		if (0 == link.refCount_)
		{
			// One more task has no dependencies, place it to the ready list
			readyTasksList_.AddHead(link.pTask_);
		}
		else 
		{
			// Update the link's reference count in the hash
			allTasksLinkMap_[pTask->GetId()] = link;
		}
	}
}
void CRUTopologicalDGIterator::Build()
{
	TaskLink link;

	// Fill the data structures by references to available tasks
	DSListPosition pos = GetAllTasksList().GetHeadPosition();
	while (NULL != pos)
	{
		CRUTask *pTask = GetAllTasksList().GetNext(pos);
		link.pTask_ = pTask;

		// The tasks that need to be traversed before me
		CRUTaskList &refTaskList =
			(DIRECT == dir_) ? 
				pTask->GetTasksThatIDependOn() :
				pTask->GetTasksThatDependOnMe();
			
		link.refCount_ = refTaskList.GetCount();
		
		// Place the link into the hash
		allTasksLinkMap_[pTask->GetId()] = link;

		// If this is a ready task, 
		// place a reference to it into the ready list
		if (0 == link.refCount_)
		{
			readyTasksList_.AddHead(link.pTask_);
		}
	}

	// My guess is that this is a circular graph
	RUASSERT(FALSE == readyTasksList_.IsEmpty()); 

	SetCurrentTask(readyTasksList_.RemoveHead());
}
예제 #3
0
//--------------------------------------------------------------------------//
//	CRUTask::Dump()
//
//	Called by CRUDependenceGraph::Dump()
//
//	Prints the "standard" task's dump
//--------------------------------------------------------------------------//
// LCOV_EXCL_START :dpm
void CRUTask::Dump(CDSString &to)
{
    char idStr[10];
    sprintf(idStr,"%d",GetId());

    to += "\nTASK ID = " + CDSString(idStr);
    to += "\n\t" + GetTaskName() + "\n";

    if (0 == pSuccList_->GetCount())
    {
        to += "\tNo tasks depend on me.\n";
    }
    else
    {
        to += "\tTasks that depend on me:\n";

        DSListPosition pos = pSuccList_->GetHeadPosition();
        while (NULL != pos)
        {
            CRUTask *pTask = pSuccList_->GetNext(pos);
            sprintf(idStr,"%d",pTask->GetId());
            to += "\t\tTask id = " + CDSString(idStr) + "\n";
        }
    }
}
예제 #4
0
CRUTask *CRUTaskList::FindTask(Lng32 taskId)
{
    DSListPosition pos = GetHeadPosition();

    while (NULL != pos)
    {
        CRUTask *pTask = GetNext(pos);
        if (pTask->GetId() == taskId)
        {
            return pTask;
        }
    }

    return NULL;
}
예제 #5
0
//--------------------------------------------------------------------------//
//	CRUTask::DumpGraphNode()
//
//	Called by CRUDependenceGraph::DumpGraph()
//
//	Prints the task's edges dump acceptable for the Dotty GUI
//
//--------------------------------------------------------------------------//
// LCOV_EXCL_START :dpm
void CRUTask::DumpGraphEdges(CDSString &to)
{
    if (0 == pSuccList_->GetCount())
    {
        return;
    }

    char fromChr[10],toChr[10];
    sprintf(fromChr,"%d",GetId());

    CDSString fromStr(fromChr);
    fromStr = "\t\t" + fromStr + " -> ";

    DSListPosition pos = pSuccList_->GetHeadPosition();
    while (NULL != pos)
    {
        CRUTask *pTask = pSuccList_->GetNext(pos);
        sprintf(toChr,"%d",pTask->GetId());
        to += fromStr + CDSString(toChr) + ";\n";
    }
}