package nachos.threads;
import nachos.machine.*;
/**
* A multi-threaded OS kernel.
*/
public class ThreadedKernel extends Kernel {
/**
* Allocate a new multi-threaded kernel.
*/
public ThreadedKernel() {
super();
}
/**
* Initialize this kernel. Creates a scheduler, the first thread, and an
* alarm, and enables interrupts. Creates a file system if necessary.
*/
public void initialize(String[] args) {
// set scheduler
String schedulerName = Config.getString("ThreadedKernel.scheduler");
scheduler = (Scheduler) Lib.constructObject(schedulerName);
// set fileSystem
String fileSystemName = Config.getString("ThreadedKernel.fileSystem");
if (fileSystemName != null)
fileSystem = (FileSystem) Lib.constructObject(fileSystemName);
else if (Machine.stubFileSystem() != null) fileSystem = Machine.stubFileSystem(); else
fileSystem = null;
// start threading
new KThread(null);
alarm = new Alarm();
Machine.interrupt().enable();
}
/**
* Test this kernel. Test various classes.
*/
public void selfTest() {
System.out.println("\n*** Nachos Kernel Successfull Started ***\n");
//KThread.selfTest();
//KThread.simpleSelfTest();
//Semaphore.selfTest();
//Condition.selfTest();
//Condition2.selfTest();
//Alarm.selfTest();
//Communicator.selfTest();
PriorityScheduler.selfTest();
}
/**
* A threaded kernel does not run user programs, so this method does
* nothing.
*/
public void run() {
}
/**
* Terminate this kernel. Never returns.
*/
public void terminate() {
Machine.halt();
}
/** Globally accessible reference to the scheduler. */
public static Scheduler scheduler = null;
/** Globally accessible reference to the alarm. */
public static Alarm alarm = null;
/** Globally accessible reference to the file system. */
public static FileSystem fileSystem = null;
// dummy variables to make javac smarter
private static RoundRobinScheduler dummy1 = null;
private static PriorityScheduler dummy2 = null;
private static LotteryScheduler dummy3 = null;
private static Condition2 dummy4 = null;
private static Communicator dummy5 = null;
private static Rider dummy6 = null;
private static ElevatorController dummy7 = null;
}