Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

POScheduler.java

00001 package gov.nasa.arc.ase.jpf.jvm;
00002 
00003 import gov.nasa.arc.ase.jpf.iSystemState;
00004 import gov.nasa.arc.ase.jpf.iThreadInfo;
00005 import gov.nasa.arc.ase.jpf.JPFErrorException;
00006 
00007 public class POScheduler extends Scheduler {
00008   private static final int NONE = -1;
00009   private static final int UNKNOWN = -2;
00010 
00011   private int thread;
00012   private int random;
00013   private boolean lastRandom;
00014   private int safeThread;
00015   private boolean safeMove;
00016 
00017   public POScheduler(iSystemState ss) {
00018     initialize(ss);
00019   }  
00020   public POScheduler(POScheduler ps) {
00021     thread = ps.thread;
00022     random = ps.random;
00023     lastRandom = ps.lastRandom;
00024     safeThread = ps.safeThread;
00025     safeMove = ps.safeMove;
00026     ss = null;
00027   }  
00028   public Object clone() {
00029     return new POScheduler(this);
00030   }  
00031   public void failedProviso() {
00032     safeMove = false;
00033     thread = 0;
00034     random = 0;
00035     lastRandom = true;
00036   }  
00037   public int getRandom() {
00038     return random;
00039   }  
00040   public int getThread() {
00041     return thread;
00042   }  
00043   public void initialize(iSystemState ss) {
00044     this.ss = (SystemState)ss;
00045     thread = 0;
00046     random = 0;
00047     lastRandom = true;
00048     safeThread = UNKNOWN;
00049     safeMove = false;
00050   }  
00051   public iThreadInfo locateThread(iSystemState ss) {
00052     int limit = ss.getThreadCount();
00053     int unsafeThread = -1;
00054 
00055     if(safeMove) return null;
00056 
00057     if(safeThread == UNKNOWN) {
00058       // check for a safe move the first time
00059       for(int n = ss.getThreadCount(); thread < n; thread++) {
00060     iThreadInfo th = ss.getThreadInfo(thread);
00061 
00062     if(th.isSafe() && th.isRunnable()) {
00063       safeThread = thread;
00064       safeMove = true;
00065       return th;
00066     }
00067       }
00068       thread = 0;
00069       safeThread = NONE;
00070     }
00071 
00072     for(int n = ss.getThreadCount(); thread < n; thread++)
00073       if(thread != safeThread) {
00074     iThreadInfo th = ss.getThreadInfo(thread);
00075 
00076     if(th.isRunnable())
00077       return th;
00078       }
00079 
00080     return null;
00081   }  
00082   public void next() {
00083     if(safeMove)
00084       ((SystemState)ss).ti.addComment("safe move");
00085     else
00086       ((SystemState)ss).ti.addComment("non safe move");
00087     if(lastRandom) {
00088       random = 0;
00089       thread++;
00090     } else {
00091       random++;
00092     }
00093   }  
00094   public int random(int max) {
00095     lastRandom = (random == max-1);
00096 
00097     return random;
00098   }  
00099 }

Generated at Thu Feb 7 06:52:11 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001