Added currentTimeMillis() which makes a small effort to cope with the
WinXP time fluctuation problem. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1178 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
//
|
||||
// $Id: RunAnywhere.java,v 1.4 2003/07/12 02:46:03 ray Exp $
|
||||
// $Id: RunAnywhere.java,v 1.5 2003/07/29 00:43:54 mdb Exp $
|
||||
|
||||
package com.samskivert.util;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
|
||||
import com.samskivert.Log;
|
||||
|
||||
/**
|
||||
* <cite>Write once, run anywhere.</cite> Well, at least that's what it
|
||||
* said in the brochures. For those less than fresh days, you might need
|
||||
@@ -39,6 +41,32 @@ public class RunAnywhere
|
||||
return _isLinux;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@link System#currentTimeMillis}, but works around a bug on
|
||||
* WinXP that causes time to sometimes leap into the past.
|
||||
*/
|
||||
public static final long currentTimeMillis ()
|
||||
{
|
||||
long stamp = System.currentTimeMillis();
|
||||
|
||||
// on WinXP the time sometimes seems to leap into the past; here
|
||||
// we do what we can to work around this insanity by simply
|
||||
// stopping time rather than allowing it to go into the past
|
||||
if (stamp < _lastStamp) {
|
||||
// only warn once per time anomaly
|
||||
if (stamp > _lastWarning) {
|
||||
Log.warning("Someone call Einstein! The clock is " +
|
||||
"running backwards [dt=" +
|
||||
(stamp - _lastStamp) + "].");
|
||||
_lastWarning = _lastStamp;
|
||||
}
|
||||
stamp = _lastStamp;
|
||||
}
|
||||
_lastStamp = stamp;
|
||||
|
||||
return stamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp associated with the supplied event except on
|
||||
* the Macintosh where it returns {@link System#currentTimeMillis}
|
||||
@@ -48,7 +76,7 @@ public class RunAnywhere
|
||||
*/
|
||||
public static long getWhen (InputEvent event)
|
||||
{
|
||||
return (isWindows() || isMacOS()) ? System.currentTimeMillis()
|
||||
return (isWindows() || isMacOS()) ? currentTimeMillis()
|
||||
: event.getWhen();
|
||||
}
|
||||
|
||||
@@ -64,6 +92,9 @@ public class RunAnywhere
|
||||
* is first loaded. */
|
||||
protected static boolean _isLinux;
|
||||
|
||||
/** Used to ensure that the timer is sane. */
|
||||
protected static long _lastStamp, _lastWarning;
|
||||
|
||||
static {
|
||||
try {
|
||||
String osname = System.getProperty("os.name");
|
||||
|
||||
Reference in New Issue
Block a user