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 DefaultScheduler extends Scheduler {
00008 private int thread;
00009 private int random;
00010 private boolean lastRandom;
00011
00012 public DefaultScheduler(iSystemState ss) {
00013 initialize(ss);
00014 }
00015 public DefaultScheduler(DefaultScheduler ds) {
00016 thread = ds.thread;
00017 random = ds.random;
00018 lastRandom = ds.lastRandom;
00019 ss = null;
00020 }
00021 public Object clone() {
00022 return new DefaultScheduler(this);
00023 }
00024 public int getRandom() {
00025 return random;
00026 }
00027 public int getThread() {
00028 return thread;
00029 }
00030 public void initialize(iSystemState ss) {
00031 this.ss = (SystemState)ss;
00032 thread = 0;
00033 random = 0;
00034 lastRandom = true;
00035 }
00036 public iThreadInfo locateThread(iSystemState ss) {
00037
00038 for(int n = ss.getThreadCount(); thread < n; thread++) {
00039 iThreadInfo th = ss.getThreadInfo(thread);
00040
00041 if(th.isRunnable())
00042 return th;
00043 }
00044
00045 return null;
00046 }
00047 public void next() {
00048 if(lastRandom) {
00049 random = 0;
00050 thread++;
00051 } else {
00052 random++;
00053 }
00054 }
00055 public int random(int max) {
00056 lastRandom = (random == max-1);
00057
00058 return random;
00059 }
00060 }