summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/concurrent/SyncVar.scala35
1 files changed, 10 insertions, 25 deletions
diff --git a/src/library/scala/concurrent/SyncVar.scala b/src/library/scala/concurrent/SyncVar.scala
index 46dc415e1f..5b55be1326 100644
--- a/src/library/scala/concurrent/SyncVar.scala
+++ b/src/library/scala/concurrent/SyncVar.scala
@@ -6,12 +6,10 @@
** |/ **
\* */
-
-
package scala.concurrent
-
-/** The class <code>SyncVar</code> ...
+/** A class to provide safe concurrent access to a mutable cell.
+ * All methods are synchronized.
*
* @author Martin Odersky, Stepan Koltsov
* @version 1.0, 10/03/2003
@@ -29,24 +27,17 @@ class SyncVar[A] {
def get(timeout: Long): Option[A] = synchronized {
if (!isDefined) {
- try {
- wait(timeout)
- } catch {
- case _: InterruptedException =>
- }
+ try wait(timeout)
+ catch { case _: InterruptedException => () }
}
- if (exception.isEmpty) {
- if (isDefined) Some(value) else None
- } else
- throw exception.get
+ if (exception.isDefined) throw exception.get
+ else if (isDefined) Some(value)
+ else None
}
def take() = synchronized {
- try {
- get
- } finally {
- unset()
- }
+ try get
+ finally unset()
}
def set(x: A) = synchronized {
@@ -56,12 +47,6 @@ class SyncVar[A] {
notifyAll()
}
- private def setException(e: Throwable) = synchronized {
- exception = Some(e)
- isDefined = true
- notifyAll()
- }
-
def put(x: A) = synchronized {
while (isDefined) wait()
set(x)
@@ -75,5 +60,5 @@ class SyncVar[A] {
isDefined = false
notifyAll()
}
-
}
+