nachos.machine
Class Interrupt

java.lang.Object
  extended by nachos.machine.Interrupt

public final class Interrupt
extends Object

The Interrupt class emulates low-level interrupt hardware. The hardware provides a method (setStatus()) to enable or disable interrupts.

In order to emulate the hardware, we need to keep track of all pending interrupts the hardware devices would cause, and when they are supposed to occur.

This module also keeps track of simulated time. Time advances only when the following occur:

As a result, unlike real hardware, interrupts (including time-slice context switches) cannot occur just anywhere in the code where interrupts are enabled, but rather only at those places in the code where simulated time advances (so that it becomes time for the hardware simulation to invoke an interrupt handler).

This means that incorrectly synchronized code may work fine on this hardware simulation (even with randomized time slices), but it wouldn't work on real hardware. But even though Nachos can't always detect when your program would fail in real life, you should still write properly synchronized code.


Constructor Summary
Interrupt(Privilege privilege)
          Allocate a new interrupt controller.
 
Method Summary
 boolean disable()
          Disable interrupts and return the old interrupt state.
 boolean disabled()
          Tests whether interrupts are disabled.
 void enable()
          Enable interrupts.
 boolean enabled()
          Tests whether interrupts are enabled.
 void restore(boolean status)
          Restore interrupts to the specified status.
 boolean setStatus(boolean status)
          Set the interrupt status to be enabled (true) or disabled (false) and return the previous status.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Interrupt

public Interrupt(Privilege privilege)
Allocate a new interrupt controller.

Parameters:
privilege - encapsulates privileged access to the Nachos machine.
Method Detail

enable

public void enable()
Enable interrupts. This method has the same effect as setStatus(true).


disable

public boolean disable()
Disable interrupts and return the old interrupt state. This method has the same effect as setStatus(false).

Returns:
true if interrupts were enabled.

restore

public void restore(boolean status)
Restore interrupts to the specified status. This method has the same effect as setStatus(status).

Parameters:
status - true to enable interrupts.

setStatus

public boolean setStatus(boolean status)
Set the interrupt status to be enabled (true) or disabled (false) and return the previous status. If the interrupt status changes from disabled to enabled, the simulated time is advanced.

Parameters:
status - true to enable interrupts.
Returns:
true if interrupts were enabled.

enabled

public boolean enabled()
Tests whether interrupts are enabled.

Returns:
true if interrupts are enabled.

disabled

public boolean disabled()
Tests whether interrupts are disabled.

Returns:
true if interrupts are disabled.