A pluggable timer system that will eventually provide a native code-based

high resolution timer.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1967 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-11-20 02:17:38 +00:00
parent 128547b41b
commit ac3e732f9b
2 changed files with 71 additions and 0 deletions
@@ -0,0 +1,34 @@
//
// $Id: MediaTimer.java,v 1.1 2002/11/20 02:17:38 mdb Exp $
package com.threerings.media.timer;
/**
* Provides a pluggable mechanism for delivering high resolution timing
* information. The timers are not intended to be used by different
* threads and thus must be protected by synchronization in such
* circumstances.
*/
public interface MediaTimer
{
/**
* Resets the timer's monotonically increasing value.
*/
public void reset ();
/**
* Returns the number of milliseconds that have elapsed since the
* timer was created or last {@link #reset}. <em>Note:</em> the
* accuracy of this method is highly dependent on the timer
* implementation used.
*/
public long getElapsedMillis ();
/**
* Returns the number of microseconds that have elapsed since the
* timer was created or last {@link #reset}. <em>Note:</em> the
* accuracy of this method is highly dependent on the timer
* implementation used.
*/
public long getElapsedMicros ();
}
@@ -0,0 +1,37 @@
//
// $Id: SystemMediaTimer.java,v 1.1 2002/11/20 02:17:38 mdb Exp $
package com.threerings.media.timer;
/**
* Implements the {@link MediaTimer} interface using {@link
* System#currentTimeMillis} to obtain timing information.
*
* <p> <em>Note:</em> {@link System#currentTimeMillis} is notoriously
* inaccurate on different platforms. See <a
* href="http://developer.java.sun.com/developer/bugParade/bugs/4486109.html">
* bug report 4486109</a> for more information.
*/
public class SystemMediaTimer implements MediaTimer
{
// documentation inherited from interface
public void reset ()
{
_resetStamp = System.currentTimeMillis();
}
// documentation inherited from interface
public long getElapsedMillis ()
{
return System.currentTimeMillis() - _resetStamp;
}
// documentation inherited from interface
public long getElapsedMicros ()
{
return getElapsedMillis() * 10;
}
/** The time at which this timer was last reset. */
protected long _resetStamp = System.currentTimeMillis();
}