diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-01-26 08:37:23 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-01-26 08:37:23 +0000 |
commit | 78a48c46cf3727dd06179cb1360b2f9057647042 (patch) | |
tree | 01f418fab8ee1cd61c5a6a891bdce09cde142098 /src/library/scala/concurrent/SyncVar.scala | |
parent | 78007ac467c9d6e88ae183a9126772829072704c (diff) | |
download | scala-78a48c46cf3727dd06179cb1360b2f9057647042.tar.gz scala-78a48c46cf3727dd06179cb1360b2f9057647042.tar.bz2 scala-78a48c46cf3727dd06179cb1360b2f9057647042.zip |
Merge branch 'work'
Conflicts:
src/library/scala/concurrent/SyncVar.scala
Diffstat (limited to 'src/library/scala/concurrent/SyncVar.scala')
-rw-r--r-- | src/library/scala/concurrent/SyncVar.scala | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/src/library/scala/concurrent/SyncVar.scala b/src/library/scala/concurrent/SyncVar.scala index 61f8188ab1..bf39fef27c 100644 --- a/src/library/scala/concurrent/SyncVar.scala +++ b/src/library/scala/concurrent/SyncVar.scala @@ -36,16 +36,40 @@ class SyncVar[A] { * by counting time elapsed directly. Loop required * to deal with spurious wakeups. */ - var rest = timeout - while (!isDefined && rest >= 0) { - val elapsed = waitMeasuringElapsed(timeout) - if (!isDefined && elapsed > 0) - rest -= elapsed - } - if (isDefined) Some(value) - else None + var rest = timeout + while (!isDefined && rest >= 0) { + val elapsed = waitMeasuringElapsed(timeout) + if (!isDefined && elapsed > 0) + rest -= elapsed + } + if (isDefined) Some(value) + else None } + // /** Waits for this SyncVar to become defined at least for + // * `timeout` milliseconds (possibly more), and gets its + // * value. + // * + // * @param timeout the amount of milliseconds to wait + // * @return `None` if variable is undefined after `timeout`, `Some(value)` otherwise + // */ + // def get(timeout: Long): Option[A] = synchronized { + // if (timeout == 0L) Some(get) + // else { + // val start = System.currentTimeMillis + // var left = timeout + // while (!isDefined && left > 0) { + // wait(left) + // if (!isDefined) { + // val elapsed = System.currentTimeMillis - start + // left = timeout - elapsed + // } + // } + // if (isDefined) Some(value) + // else None + // } + // } + def take() = synchronized { try get finally unset() |