Logo Search packages:      
Sourcecode: scala version File versions  Download package

void scala::actors::FJTaskRunner::checkOverflow (  )  [inline, protected]

Adjust top and base, and grow DEQ if necessary. Called only while DEQ synch lock being held. We don't expect this to be called very often. In most programs using FJTasks, it is never called.

Definition at line 581 of file FJTaskRunner.java.

References base, deq, MAX_CAPACITY, scala::actors::FJTaskRunner::VolatileTaskRef::ref, and top.

Referenced by put(), and slowPush().

                                 { 
    int t = top;
    int b = base;
    
    if (t - b < deq.length-1) { // check if just need an index reset
      
      int newBase = b & (deq.length-1);
      int newTop  = top & (deq.length-1);
      if (newTop < newBase) newTop += deq.length;
      top = newTop;
      base = newBase;
      
      /* 
         Null out refs to stolen tasks. 
         This is the only time we can safely do it.
      */
      
      int i = newBase;
      while (i != newTop && deq[i].ref != null) {
        deq[i].ref = null;
        i = (i - 1) & (deq.length-1);
      }
      
    }
    else { // grow by doubling array
      
      int newTop = t - b;
      int oldcap = deq.length;
      int newcap = oldcap * 2;
      
      if (newcap >= MAX_CAPACITY)
        throw new Error("FJTask queue maximum capacity exceeded");
      
      VolatileTaskRef[] newdeq = new VolatileTaskRef[newcap];
      
      // copy in bottom half of new deq with refs from old deq
      for (int j = 0; j < oldcap; ++j) newdeq[j] = deq[b++ & (oldcap-1)];
      
      // fill top half of new deq with new refs
      for (int j = oldcap; j < newcap; ++j) newdeq[j] = new VolatileTaskRef();
      
      deq = newdeq;
      base = 0;
      top = newTop;
    }
  }


Generated by  Doxygen 1.6.0   Back to index