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

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

Same as scan, but called when current thread is idling. It repeatedly scans other threads for tasks, sleeping while none are available.

This differs from scan mainly in that since there is no reason to return to recheck any condition, we iterate until a task is found, backing off via sleeps if necessary.

Definition at line 724 of file FJTaskRunner.java.

References scala::actors::IFJTaskRunnerGroup::checkActive(), COLLECT_STATS, scala::actors::IFJTaskRunnerGroup::getArray(), group, scala::actors::FJTask::isDone(), scala::actors::IFJTaskRunnerGroup::pollEntryQueue(), runPriority, runs, scanPriority, scans, scala::actors::IFJTaskRunnerGroup::setActive(), scala::actors::FJTask::setDone(), steals, take(), and victimRNG.

Referenced by run().

                                   {
    FJTask task = null;
    
    boolean lowered = false;
    long iters = 0;
    
    FJTaskRunner[] ts = group.getArray();
    int idx = victimRNG.nextInt(ts.length);
    
    do {
      for (int i = 0; i < ts.length; ++i) {
        
        FJTaskRunner t = ts[idx];
        if (++idx >= ts.length) idx = 0; // circularly traverse
        
        if (t != null && t != this) {
          if (COLLECT_STATS) ++scans;
          
          task = t.take();
          if (task != null) {
            if (COLLECT_STATS) ++steals;
            if (lowered) setPriority(runPriority);
            group.setActive(this);
            break;
          }
        }
      } 
      
      if (task == null) {
        if (isInterrupted()) 
          return;
        
        if (COLLECT_STATS) ++scans;
        task = group.pollEntryQueue();
        
        if (task != null) {
          if (COLLECT_STATS) ++steals;
          if (lowered) setPriority(runPriority);
          group.setActive(this);
        }
        else {
          ++iters;
          //  Check here for yield vs sleep to avoid entering group synch lock
          if (iters >= /*group.SCANS_PER_SLEEP*/ 15) {
            group.checkActive(this, iters);
            if (isInterrupted())
              return;
          }
          else if (!lowered) {
            lowered = true;
            setPriority(scanPriority);
          }
          else {
            yield();
          }
        }
      }
    } while (task == null);


    if (!task.isDone()) {
      if (COLLECT_STATS) ++runs;
      task.run(); 
      task.setDone(); 
    }
    
  }


Generated by  Doxygen 1.6.0   Back to index