diff options
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/concurrent/SyncVar.scala | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/library/scala/concurrent/SyncVar.scala b/src/library/scala/concurrent/SyncVar.scala index 76d21c3dbf..d5dc3d7e3f 100644 --- a/src/library/scala/concurrent/SyncVar.scala +++ b/src/library/scala/concurrent/SyncVar.scala @@ -8,6 +8,8 @@ package scala.concurrent +import java.util.concurrent.TimeUnit + /** A class to provide safe concurrent access to a mutable cell. * All methods are synchronized. * @@ -23,14 +25,16 @@ class SyncVar[A] { value.get } - /** Waits `timeout` millis. If `timeout <= 0` just returns 0. If the system clock - * went backward, it will return 0, so it never returns negative results. - */ + /** Waits `timeout` millis. If `timeout <= 0` just returns 0. + * It never returns negative results. + */ private def waitMeasuringElapsed(timeout: Long): Long = if (timeout <= 0) 0 else { - val start = System.currentTimeMillis + val start = System.nanoTime() wait(timeout) - val elapsed = System.currentTimeMillis - start - if (elapsed < 0) 0 else elapsed + val elapsed = System.nanoTime() - start + // nanoTime should be monotonic, but it's not possible to rely on that. + // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6458294. + if (elapsed < 0) 0 else TimeUnit.NANOSECONDS.toMillis(elapsed) } /** Waits for this SyncVar to become defined at least for |