de.michab.simulator
Class Clock

java.lang.Object
  extended byde.michab.simulator.Clock

public class Clock
extends java.lang.Object

The central clock management for an emulation. Represents a clock with configurable resolution. The clock is the synchronisation point for the emulation time and is also responsible to keep in sync with real time, that is, if the emulation is faster than real time, the clock throttles the emulation by performing intermediate sleep cycles.

Actual communication from the clock and clock clients is performed through an instance of Clock.ClockHandle created by a call to register().

TODO debugging, in this case emulation is *much* slower, so sync is meaningless.

Version:
$Revision: 1.13 $
Author:
Michael Binz

Nested Class Summary
 class Clock.ClockHandle
          Each clock client receives a ClockHandle as the result of performing the register() operation.
 
Constructor Summary
Clock(long ticksPerSecond)
          Creates a clock with the specified frequency.
 
Method Summary
 long currentTime()
          Get the clock's current time.
 long getResolution()
          Get the clock's resolution in ticks per second.
 Clock.ClockHandle register()
          Registers a client with this clock.
 void start()
          Starts dispatching.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Clock

public Clock(long ticksPerSecond)
Creates a clock with the specified frequency.

Parameters:
ticksPerSecond - This clock's frequency.
Method Detail

start

public void start()
Starts dispatching. This will ensure that all registered clients have successfully called prepare() before thread scheduling is started.


register

public Clock.ClockHandle register()
Registers a client with this clock. Note that registration is only allowed before the clock has been started.

Returns:
A clock handle that represents the client's main interface to the clock.
Throws:
java.lang.IllegalStateException - When the clock has been started yet.
See Also:
start()

currentTime

public long currentTime()
Get the clock's current time. This is the minimum time across all associated chips.

Returns:
The clock's federated current time.

getResolution

public long getResolution()
Get the clock's resolution in ticks per second.

Returns:
The clock's resolution.