Skip to content

Commit

Permalink
Add documentation to parts of scala.concurrent.
Browse files Browse the repository at this point in the history
  • Loading branch information
tvierling committed Jun 3, 2014
1 parent b24e757 commit 0d5fa2a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
17 changes: 13 additions & 4 deletions src/library/scala/concurrent/Channel.scala
Expand Up @@ -10,8 +10,10 @@

package scala.concurrent

/** This class ...
/** This class provides a simple FIFO queue of data objects,
* which are read by one or more reader threads.
*
* @tparam A type of data exchanged
* @author Martin Odersky
* @version 1.0, 10/03/2003
*/
Expand All @@ -20,11 +22,14 @@ class Channel[A] {
var elem: A = _
var next: LinkedList[A] = null
}
private var written = new LinkedList[A] // FIFO buffer, realized through
private var written = new LinkedList[A] // FIFO queue, realized through
private var lastWritten = written // aliasing of a linked list
private var nreaders = 0

/**
/** Append a value to the FIFO queue to be read by `read`.
* This operation is nonblocking and can be executed by any thread.
*
* @param x object to enqueue to this channel
*/
def write(x: A) = synchronized {
lastWritten.elem = x
Expand All @@ -33,6 +38,11 @@ class Channel[A] {
if (nreaders > 0) notify()
}

/** Retrieve the next waiting object from the FIFO queue,
* blocking if necessary until an object is available.
*
* @return next object dequeued from this channel
*/
def read: A = synchronized {
while (written.next == null) {
try {
Expand All @@ -45,5 +55,4 @@ class Channel[A] {
written = written.next
x
}

}
4 changes: 2 additions & 2 deletions src/library/scala/concurrent/ExecutionContext.scala
Expand Up @@ -77,12 +77,12 @@ trait ExecutionContext {
}

/**
* Union interface since Java does not support union types
* An [[ExecutionContext]] that is also a Java [[Executor]].
*/
trait ExecutionContextExecutor extends ExecutionContext with Executor

/**
* Union interface since Java does not support union types
* An [[ExecutionContext]] that is also a Java [[ExecutorService]].
*/
trait ExecutionContextExecutorService extends ExecutionContextExecutor with ExecutorService

Expand Down
16 changes: 13 additions & 3 deletions src/library/scala/concurrent/SyncVar.scala
Expand Up @@ -13,13 +13,20 @@ import java.util.concurrent.TimeUnit
/** A class to provide safe concurrent access to a mutable cell.
* All methods are synchronized.
*
* @tparam A type of the contained value
* @author Martin Odersky
* @version 1.0, 10/03/2003
*/
class SyncVar[A] {
private var isDefined: Boolean = false
private var value: Option[A] = None

/**
* Waits for this SyncVar to become defined and returns
* the result, without modifying the stored value.
*
* @return value that is held in this container
*/
def get: A = synchronized {
while (!isDefined) wait()
value.get
Expand Down Expand Up @@ -57,8 +64,12 @@ class SyncVar[A] {
value
}

/** Waits for this SyncVar to become defined and returns
* the result */
/**
* Waits for this SyncVar to become defined and returns
* the result, unsetting the stored value before returning.
*
* @return value that was held in this container
*/
def take(): A = synchronized {
try get
finally unsetVal()
Expand Down Expand Up @@ -129,4 +140,3 @@ class SyncVar[A] {
}

}

5 changes: 5 additions & 0 deletions src/library/scala/concurrent/package.scala
Expand Up @@ -55,6 +55,11 @@ package object concurrent {
}

package concurrent {
/**
* This marker trait is used by [[Await]] to ensure that [[Awaitable.ready]] and [[Awaitable.result]]
* are not directly called by user code. An implicit instance of this trait is only available when
* user code is currently calling the methods on [[Await]].
*/
@implicitNotFound("Don't call `Awaitable` methods directly, use the `Await` object.")
sealed trait CanAwait

Expand Down

0 comments on commit 0d5fa2a

Please sign in to comment.