diff options
author | Sean McDirmid <sean.mcdirmid@gmail.com> | 2007-05-16 10:48:16 +0000 |
---|---|---|
committer | Sean McDirmid <sean.mcdirmid@gmail.com> | 2007-05-16 10:48:16 +0000 |
commit | 58f003be77bd2a48c4385cda75fe32148b57621d (patch) | |
tree | 62f4ba30bbf2f7b435b0f276e093108a2bdd1903 /src | |
parent | cf9f9a663f2e05747d8f32bf18332a8210198188 (diff) | |
download | scala-58f003be77bd2a48c4385cda75fe32148b57621d.tar.gz scala-58f003be77bd2a48c4385cda75fe32148b57621d.tar.bz2 scala-58f003be77bd2a48c4385cda75fe32148b57621d.zip |
Fixed race condition
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/ref/Reference.scala | 8 | ||||
-rw-r--r-- | src/library/scala/ref/ReferenceWrapper.scala | 6 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/library/scala/ref/Reference.scala b/src/library/scala/ref/Reference.scala index daebef9526..aac2e2a32a 100644 --- a/src/library/scala/ref/Reference.scala +++ b/src/library/scala/ref/Reference.scala @@ -14,10 +14,12 @@ package scala.ref * @author Sean McDirmid */ trait Reference[+T <: AnyRef] extends Function0[T] { - def isValid: Boolean + @deprecated def isValid: Boolean + /** return the underlying value */ def apply(): T - def get = if (!isValid) None else Some(apply()) - override def toString = if (!isValid) "<deleted>" else apply().toString + /** return <code>Some</code> underlying if it hasn't been collected, otherwise <code>None</code> */ + def get : Option[T] + override def toString = get.map(.toString).getOrElse("<deleted>") def clear(): Unit def enqueue(): Boolean def isEnqueued(): Boolean diff --git a/src/library/scala/ref/ReferenceWrapper.scala b/src/library/scala/ref/ReferenceWrapper.scala index 4546f4d8fd..004496d95b 100644 --- a/src/library/scala/ref/ReferenceWrapper.scala +++ b/src/library/scala/ref/ReferenceWrapper.scala @@ -15,7 +15,11 @@ package scala.ref */ trait ReferenceWrapper[+T <: AnyRef] extends Reference[T] { val underlying: java.lang.ref.Reference - def isValid = underlying.get != null + @deprecated def isValid = underlying.get != null + override def get = { + val ret = underlying.get.asInstanceOf[T] + if (ret eq null) None else Some(ret) + } def apply() = { val ret = underlying.get.asInstanceOf[T] if (ret eq null) throw new NoSuchElementException |