local SyncVar implementation to deal with std lib deprecations

This commit is contained in:
Mark Harrah 2013-05-27 19:12:39 -04:00
parent 0a7a579f5b
commit fa591364f7
2 changed files with 40 additions and 2 deletions

View File

@ -9,8 +9,6 @@ import java.io.{FilterInputStream, FilterOutputStream, PipedInputStream, PipedOu
import java.io.{File, FileInputStream, FileOutputStream}
import java.net.URL
import scala.concurrent.SyncVar
/** Runs provided code in a new Thread and returns the Thread instance. */
private object Spawn
{

View File

@ -0,0 +1,40 @@
package sbt
// minimal copy of scala.concurrent.SyncVar since that version deprecated put and unset
private[sbt] final class SyncVar[A]
{
private[this] var isDefined: Boolean = false
private[this] var value: Option[A] = None
/** Waits until a value is set and then gets it. Does not clear the value */
def get: A = synchronized {
while (!isDefined) wait()
value.get
}
/** Waits until a value is set, gets it, and finally clears the value. */
def take(): A = synchronized {
try get finally unset()
}
/** Sets the value, whether or not it is currently defined. */
def set(x: A): Unit = synchronized {
isDefined = true
value = Some(x)
notifyAll()
}
/** Sets the value, first waiting until it is undefined if it is currently defined. */
def put(x: A): Unit = synchronized {
while (isDefined) wait()
set(x)
}
/** Clears the value, whether or not it is current defined. */
def unset(): Unit = synchronized {
isDefined = false
value = None
notifyAll()
}
}