Exemplo n.º 1
0
  /**
   * Context switch between the current TCB and this TCB. This TCB will become the new current TCB.
   * It is acceptable for this TCB to be the current TCB.
   */
  public void contextSwitch() {
    /* Probably unnecessary sanity check: we make sure that the current
     * thread is bound to the current TCB. This check can only fail if
     * non-Nachos threads invoke start().
     */
    Lib.assertTrue(currentTCB.javaThread == Thread.currentThread());

    // make sure AutoGrader.runningThread() called associateThread()
    Lib.assertTrue(currentTCB.associated);
    currentTCB.associated = false;

    // can't switch from a TCB to itself
    if (this == currentTCB) return;

    /* There are some synchronization concerns here. As soon as we wake up
     * the next thread, we cannot assume anything about static variables,
     * or about any TCB's state. Therefore, before waking up the next
     * thread, we must latch the value of currentTCB, and set its running
     * flag to false (so that, in case we get interrupted before we call
     * yield(), the interrupt will set the running flag and yield() won't
     * block).
     */

    TCB previous = currentTCB;
    previous.running = false;

    this.interrupt();
    previous.yield();
  }
  /**
   * Nachos main entry point.
   *
   * @param args the command line arguments.
   */
  public static void main(final String[] args) {
    System.out.print("nachos 5.0j initializing...");

    Lib.assertTrue(Machine.args == null);
    Machine.args = args;

    processArgs();

    Config.load(configFileName);

    // get the current directory (.)
    baseDirectory = new File(new File("").getAbsolutePath());
    // get the nachos directory (./nachos)
    nachosDirectory = new File(baseDirectory, "nachos");

    String testDirectoryName = Config.getString("FileSystem.testDirectory");

    // get the test directory
    if (testDirectoryName != null) {
      testDirectory = new File(testDirectoryName);
    } else {
      // use ../test
      testDirectory = new File(baseDirectory.getParentFile(), "test");
    }

    securityManager = new NachosSecurityManager(testDirectory);
    privilege = securityManager.getPrivilege();

    privilege.machine = new MachinePrivilege();

    TCB.givePrivilege(privilege);
    privilege.stats = stats;

    securityManager.enable();
    createDevices();
    checkUserClasses();

    autoGrader = (AutoGrader) Lib.constructObject(autoGraderClassName);

    new TCB()
        .start(
            new Runnable() {
              public void run() {
                autoGrader.start(privilege);
              }
            });
  }
 /** Terminate Nachos. Same as <tt>TCB.die()</tt>. */
 public static void terminate() {
   TCB.die();
 }
Exemplo n.º 4
0
 public void authorizeDestroy(KThread thread) {
   TCB.authorizeDestroy(thread);
 }
Exemplo n.º 5
0
 public void associateThread(KThread thread) {
   Lib.assertTrue(currentTCB != null);
   currentTCB.associateThread(thread);
 }