diff options
author | michelou <michelou@epfl.ch> | 2007-07-11 14:52:34 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2007-07-11 14:52:34 +0000 |
commit | 95a9b8dc2e7b0050e6254ac114e4d2ea58512d96 (patch) | |
tree | e7cec4387f745d9d13f8299b2b99ea4a6a6ae9e5 /src/library/scala/concurrent/SyncVar.scala | |
parent | 5540988eb49493dddbc9cb00ccddb6c8e0694f43 (diff) | |
download | scala-95a9b8dc2e7b0050e6254ac114e4d2ea58512d96.tar.gz scala-95a9b8dc2e7b0050e6254ac114e4d2ea58512d96.tar.bz2 scala-95a9b8dc2e7b0050e6254ac114e4d2ea58512d96.zip |
added Stepan's patch ops/SyncVar
Diffstat (limited to 'src/library/scala/concurrent/SyncVar.scala')
-rw-r--r-- | src/library/scala/concurrent/SyncVar.scala | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/library/scala/concurrent/SyncVar.scala b/src/library/scala/concurrent/SyncVar.scala index 9b852e4cb5..6b9ca33395 100644 --- a/src/library/scala/concurrent/SyncVar.scala +++ b/src/library/scala/concurrent/SyncVar.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ @@ -14,24 +14,43 @@ package scala.concurrent /** The class <code>SyncVar</code> ... * - * @author Martin Odersky + * @author Martin Odersky, Stepan Koltsov * @version 1.0, 10/03/2003 */ -class SyncVar[a] { +class SyncVar[A] { private var isDefined: Boolean = false - private var value: a = _ + private var value: A = _ + private var exception: Option[Throwable] = None def get = synchronized { while (!isDefined) wait() - value + if (exception.isEmpty) value + else throw exception.get } - def set(x: a) = synchronized { + def set(x: A) = synchronized { value = x isDefined = true + exception = None notifyAll() } + private def setException(e: Throwable) = synchronized { + exception = Some(e) + isDefined = true + notifyAll() + } + + def setWithCatch(x: => A) = synchronized { + try { + this set x + } catch { + case e => + this setException e + throw e + } + } + def isSet: Boolean = synchronized { isDefined } |