nachos.machine
Class Timer

java.lang.Object
  extended by nachos.machine.Timer
All Implemented Interfaces:
InterruptHandler

public class Timer
extends java.lang.Object
implements InterruptHandler

This class emulates a hardware timer device. A hardware timer generates a CPU interrupt every X ticks. This means it can be used for implementing time-slicing. In order to introduce some randomness into time-slicing, if "doRandom" is set, then the interrupt is comes after a random number of ticks.


Field Summary
static int DefaultInterval
          Default (average) time between timer interrupts, in ticks.
 int interval
          (Average) time between timer interrupts for this timer.
 
Constructor Summary
Timer(java.lang.String name, InterruptHandler handler)
          Initialize a hardware timer device that will generate periodic interrupts at the default interval.
Timer(java.lang.String name, InterruptHandler handler, boolean doRandom)
          Initialize a hardware timer device that will generate periodic, possibly randomized, interrupts at a default average interval.
Timer(java.lang.String name, InterruptHandler handler, int ticks)
          Initialize a hardware timer device that will generate periodic interrupts at a specified interval.
Timer(java.lang.String name, InterruptHandler handler, int ticks, boolean doRandom)
          Initialize a hardware timer device that will generate periodic, possibly randomized, interrupts with a specified average interval.
 
Method Summary
 void cancel()
          Cancel the timer object.
 void handleInterrupt()
          Method called by the machine when an interrupt occurs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DefaultInterval

public static final int DefaultInterval
Default (average) time between timer interrupts, in ticks.

See Also:
Constant Field Values

interval

public final int interval
(Average) time between timer interrupts for this timer.

Constructor Detail

Timer

public Timer(java.lang.String name,
             InterruptHandler handler,
             int ticks,
             boolean doRandom)
Initialize a hardware timer device that will generate periodic, possibly randomized, interrupts with a specified average interval.

Parameters:
name - The name of the timer, for debugging purposes.
handler - The interrupt handler object for the timer device. Its handleInterrupt() method is called with interrupts disabled every time the timer expires.
doRandom - If true, arrange for the interrupts to occur at random, instead of fixed, intervals.
ticks - The average number of ticks between interrupts.

Timer

public Timer(java.lang.String name,
             InterruptHandler handler,
             boolean doRandom)
Initialize a hardware timer device that will generate periodic, possibly randomized, interrupts at a default average interval.

Parameters:
name - The name of the timer, for debugging purposes.
handler - The interrupt handler object for the timer device. Its handleInterrupt() method is called with interrupts disabled every time the timer expires.
doRandom - If true, arrange for the interrupts to occur at random, instead of fixed, intervals.

Timer

public Timer(java.lang.String name,
             InterruptHandler handler,
             int ticks)
Initialize a hardware timer device that will generate periodic interrupts at a specified interval.

Parameters:
name - The name of the timer, for debugging purposes.
handler - The interrupt handler object for the timer device. Its handleInterrupt() method is called with interrupts disabled every time the timer expires.
ticks - The average number of ticks between interrupts.

Timer

public Timer(java.lang.String name,
             InterruptHandler handler)
Initialize a hardware timer device that will generate periodic interrupts at the default interval.

Parameters:
name - The name of the timer, for debugging purposes.
handler - The interrupt handler object for the timer device. Its handleInterrupt() method is called with interrupts disabled every time the timer expires.
Method Detail

handleInterrupt

public void handleInterrupt()
Description copied from interface: InterruptHandler
Method called by the machine when an interrupt occurs.

Specified by:
handleInterrupt in interface InterruptHandler

cancel

public void cancel()
Cancel the timer object.