//after a known path is found with DFS, use this to print cycle in reverse order
//marks dead as 1 and avoids already marked dead==1's
int PrintCycle(Node *start, Node *target, int colorVisit, FILE *outputFile)
  {
  if (start == target)
    {
    fprintf(outputFile, "%d %d %d\n", start->x, start->y, start->z);
    start->dead = 1;
    return 1;
    }
  Edge *tempNext = start->edge;
  if (tempNext == NULL || start->color == colorVisit || start->dead == 1)
    {
    return 0;
    }
  else
    {
    start->color = colorVisit;
    int tempVal = 0;
    while (0 == tempVal && tempNext != NULL)
      {
      tempVal = PrintCycle(tempNext->node, target, colorVisit, outputFile);
      tempNext = tempNext->edge;
      }
    if (1 == tempVal)
      {
      start->dead = 1;
      fprintf(outputFile, "%d %d %d\n", start->x, start->y, start->z);
      }
    return tempVal;
    }
  }
예제 #2
0
void execute_pipeline(){

	
	cycle = 0;

	while(1){

			
		
		
		register_output();
		WriteBack();
		DataMemoryAccess();
		Execute();
		InstrDecode();
		InstrFetch();
		PrintCycle(PC, cycle++);
		if(halt_error == 1) return;
		if(ID_EX.opcode == halt && EX_DM.opcode == halt && DM_WB.opcode == halt && precedent.opcode == halt)
			return;
	}
}
void
BlockingResourceBase::CheckAcquire(const CallStack& aCallContext)
{
    if (eCondVar == mDDEntry->mType) {
        NS_NOTYETIMPLEMENTED(
            "FIXME bug 456272: annots. to allow CheckAcquire()ing condvars");
        return;
    }

    BlockingResourceBase* chainFront = ResourceChainFront();
    nsAutoPtr<DDT::ResourceAcquisitionArray> cycle(
        sDeadlockDetector->CheckAcquisition(
            chainFront ? chainFront->mDDEntry : 0, mDDEntry,
            aCallContext));
    if (!cycle)
        return;

    fputs("###!!! ERROR: Potential deadlock detected:\n", stderr);
    nsCAutoString out("Potential deadlock detected:\n");
    bool maybeImminent = PrintCycle(cycle, out);

    if (maybeImminent) {
        fputs("\n###!!! Deadlock may happen NOW!\n\n", stderr);
        out.Append("\n###!!! Deadlock may happen NOW!\n\n");
    } else {
        fputs("\nDeadlock may happen for some other execution\n\n",
              stderr);
        out.Append("\nDeadlock may happen for some other execution\n\n");
    }

    // XXX can customize behavior on whether we /think/ deadlock is
    // XXX about to happen.  for example:
    // XXX   if (maybeImminent)
    //           NS_RUNTIMEABORT(out.get());
    NS_ERROR(out.get());
}
void buildCycles(double *dist, int *segs, int sizeHeap, 
                 Parent *sets, Node *nodes, FILE *outputFile, int maxComponents)
  {
  //note: heap should already be built.
  int curHeapLength = sizeHeap;
  int unions= 0;  //counters, useful for debugging
  int nons= 0;
  int continueFinding = 0; //increments when componentfound
  for (int i = sizeHeap - 1; i > -1 && maxComponents > continueFinding ; i--)
    {
    double minDist = GetAlphaDist(dist, 0);
    int fx = GetAlphaSeg(segs, 0, 0, 0);
    int fy = GetAlphaSeg(segs, 0, 1, 0);
    int fz = GetAlphaSeg(segs, 0, 2, 0);
    int tx = GetAlphaSeg(segs, 0, 0, 1);
    int ty = GetAlphaSeg(segs, 0, 1, 1);
    int tz = GetAlphaSeg(segs, 0, 2, 1);
    SwitchAlphas(dist, segs, 0, i);    
    curHeapLength--;
    minHeapify(dist, segs, 0, curHeapLength);
    //fprintf(stderr, "%f\n", minDist);
    //fprintf(stderr, "%f (%d %d %d) (%d %d %d)\n", minDist, fx, fy, fz, tx, ty, tz);
    //now we process the two points.
    //fprintf(stderr, "%d %d\n", calcIndexN(fx, fy, fz), calcIndexN(tx, ty, tz));
    //we need these several places
    int fromIndex = calcIndexN(fx,fy,fz);
    int toIndex = calcIndexN(tx,ty,tz);
    if (Value(sets[fromIndex]) != Value(sets[toIndex]))
      {
      Union(&sets[fromIndex], &sets[toIndex]);
      //and add edge to new graph from fx,y,z to tx,y,z
      Edge *newEdge = (Edge *)malloc(sizeof(Edge));
      newEdge->node = &nodes[toIndex];
      newEdge->edge = NULL;
      newEdge->dist = minDist;
      if (nodes[fromIndex].edge == NULL)
        {
        nodes[fromIndex].edge = newEdge;
        }
      else
        {
        Edge *temp = nodes[fromIndex].edge;
        while (temp->edge != NULL)
          {
          temp = temp->edge;
          }
        temp->edge = newEdge;
        }
      unions++;
      }
    else
      {
      //fprintf(stderr, "%d %d\n"  ,Value(sets[calcIndexN(fx, fy, fz)]) ,Value(sets[calcIndexN(tx, ty, tz)]));
      //search, find and output! (or discard)
      int success = DepthFirstSearch(&nodes[toIndex], &nodes[fromIndex], nons);
      if (1 == success)
        {
        //fprintf(stderr, "cycle from %d %d %d to %d %d %d\n", tx, ty, tz, fx, fy, fz);
        nons++;
        continueFinding++; //stop processing if goes above maxComponents
        fprintf(outputFile, "Component %d of %d:\n", continueFinding, maxComponents);
        PrintCycle(&nodes[toIndex], &nodes[fromIndex], nons, outputFile);
        fprintf(outputFile, "\n");
        }
      //do the following steps in this case no matter what, i.e. add the edge to the graph
      Edge *newEdge = (Edge *)malloc(sizeof(Edge));
      newEdge->node = &nodes[toIndex];
      newEdge->edge = NULL;
      newEdge->dist = minDist;
      if (nodes[fromIndex].edge == NULL)
        {
        nodes[fromIndex].edge = newEdge;
        }
      else
        {
        Edge *temp = nodes[fromIndex].edge;
        while (temp->edge != NULL)
          {
          temp = temp->edge;
          }
        temp->edge = newEdge;
        }
      nons++;
      }
    }  
  //fprintf(stderr, "%d %d\n", unions, nons);
  }