Skip to content

Commit

Permalink
upgrade to latest jsr166
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed Dec 14, 2013
1 parent 59d85bc commit 80ab75e
Show file tree
Hide file tree
Showing 16 changed files with 491 additions and 310 deletions.
5 changes: 4 additions & 1 deletion src/main/java/jsr166e/CompletableFuture.java
Expand Up @@ -1392,6 +1392,7 @@ public CompletableFuture() {
*
* @param supplier a function returning the value to be used
* to complete the returned CompletableFuture
* @param <U> the function's return type
* @return the new CompletableFuture
*/
public static <U> CompletableFuture<U> supplyAsync(Generator<U> supplier) {
Expand All @@ -1410,6 +1411,7 @@ public static <U> CompletableFuture<U> supplyAsync(Generator<U> supplier) {
* @param supplier a function returning the value to be used
* to complete the returned CompletableFuture
* @param executor the executor to use for asynchronous execution
* @param <U> the function's return type
* @return the new CompletableFuture
*/
public static <U> CompletableFuture<U> supplyAsync(Generator<U> supplier,
Expand Down Expand Up @@ -1462,6 +1464,7 @@ public static CompletableFuture<Void> runAsync(Runnable runnable,
* the given value.
*
* @param value the value
* @param <U> the type of the value
* @return the completed CompletableFuture
*/
public static <U> CompletableFuture<U> completedFuture(U value) {
Expand Down Expand Up @@ -2829,7 +2832,7 @@ else if (UNSAFE.compareAndSwapObject
}
if (dst == null)
dst = new CompletableFuture<U>();
if (e == null || ex != null)
if (ex != null)
dst.internalComplete(null, ex);
}
helpPostComplete();
Expand Down
363 changes: 239 additions & 124 deletions src/main/java/jsr166e/ConcurrentHashMapV8.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/jsr166e/CountedCompleter.java
Expand Up @@ -686,7 +686,7 @@ protected final boolean exec() {
}

/**
* Returns the result of the computation. By default
* Returns the result of the computation. By default,
* returns {@code null}, which is appropriate for {@code Void}
* actions, but in other cases should be overridden, almost
* always to return a field or function of a field that
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/jsr166e/ForkJoinPool.java
Expand Up @@ -532,8 +532,8 @@ public static interface ForkJoinWorkerThreadFactory {
* Returns a new worker thread operating in the given pool.
*
* @param pool the pool this thread works in
* @throws NullPointerException if the pool is null
* @return the new worker thread
* @throws NullPointerException if the pool is null
*/
public ForkJoinWorkerThread newThread(ForkJoinPool pool);
}
Expand Down Expand Up @@ -2098,7 +2098,7 @@ final void helpQuiescePool(WorkQueue w) {
w.currentSteal = ps;
}
}
else if (active) { // decrement active count without queuing
else if (active) { // decrement active count without queuing
long nc = ((c = ctl) & ~AC_MASK) | ((c & AC_MASK) - AC_UNIT);
if ((int)(nc >> AC_SHIFT) + parallelism == 0)
break; // bypass decrement-then-increment
Expand Down Expand Up @@ -2497,6 +2497,7 @@ public static ForkJoinPool commonPool() {
* minimally only the latter.
*
* @param task the task
* @param <T> the type of the task's result
* @return the task's result
* @throws NullPointerException if the task is null
* @throws RejectedExecutionException if the task cannot be
Expand Down Expand Up @@ -2545,6 +2546,7 @@ public void execute(Runnable task) {
* Submits a ForkJoinTask for execution.
*
* @param task the task to submit
* @param <T> the type of the task's result
* @return the task
* @throws NullPointerException if the task is null
* @throws RejectedExecutionException if the task cannot be
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/jsr166e/ForkJoinTask.java
Expand Up @@ -134,7 +134,7 @@
* (DAG). Otherwise, executions may encounter a form of deadlock as
* tasks cyclically wait for each other. However, this framework
* supports other methods and techniques (for example the use of
* {@link Phaser}, {@link #helpQuiesce}, and {@link #complete}) that
* {@link java.util.concurrent.Phaser Phaser}, {@link #helpQuiesce}, and {@link #complete}) that
* may be of use in constructing custom subclasses for problems that
* are not statically structured as DAGs. To support such usages, a
* ForkJoinTask may be atomically <em>tagged</em> with a {@code short}
Expand Down Expand Up @@ -411,11 +411,13 @@ static final class ExceptionNode extends WeakReference<ForkJoinTask<?>> {
final Throwable ex;
ExceptionNode next;
final long thrower; // use id not ref to avoid weak cycles
final int hashCode; // store task hashCode before weak ref disappears
ExceptionNode(ForkJoinTask<?> task, Throwable ex, ExceptionNode next) {
super(task, exceptionTableRefQueue);
this.ex = ex;
this.next = next;
this.thrower = Thread.currentThread().getId();
this.hashCode = System.identityHashCode(task);
}
}

Expand Down Expand Up @@ -571,15 +573,18 @@ else if (ps.length == 1 && ps[0] == Throwable.class)
return ex;
}

/**
* Poll stale refs and remove them. Call only while holding lock.
*/
/**
* Poll stale refs and remove them. Call only while holding lock.
*/
private static void expungeStaleExceptions() {
for (Object x; (x = exceptionTableRefQueue.poll()) != null;) {
if (x instanceof ExceptionNode) {
ForkJoinTask<?> key = ((ExceptionNode)x).get();
int hashCode = ((ExceptionNode)x).hashCode;
ExceptionNode[] t = exceptionTable;
int i = System.identityHashCode(key) & (t.length - 1);
int i = hashCode & (t.length - 1);
ExceptionNode e = t[i];
ExceptionNode pred = null;
while (e != null) {
Expand Down Expand Up @@ -782,6 +787,7 @@ else if (t.doJoin() < NORMAL)
* unprocessed.
*
* @param tasks the collection of tasks
* @param <T> the type of the values returned from the tasks
* @return the tasks argument, to simplify usage
* @throws NullPointerException if tasks or any element are null
*/
Expand Down Expand Up @@ -1444,6 +1450,7 @@ public static ForkJoinTask<?> adapt(Runnable runnable) {
*
* @param runnable the runnable action
* @param result the result upon completion
* @param <T> the type of the result
* @return the task
*/
public static <T> ForkJoinTask<T> adapt(Runnable runnable, T result) {
Expand All @@ -1457,6 +1464,7 @@ public static <T> ForkJoinTask<T> adapt(Runnable runnable, T result) {
* encountered into {@code RuntimeException}.
*
* @param callable the callable action
* @param <T> the type of the callable's result
* @return the task
*/
public static <T> ForkJoinTask<T> adapt(Callable<? extends T> callable) {
Expand All @@ -1470,6 +1478,8 @@ public static <T> ForkJoinTask<T> adapt(Callable<? extends T> callable) {
/**
* Saves this task to a stream (that is, serializes it).
*
* @param s the stream
* @throws java.io.IOException if an I/O error occurs
* @serialData the current run status and the exception thrown
* during execution, or {@code null} if none
*/
Expand All @@ -1481,6 +1491,10 @@ private void writeObject(java.io.ObjectOutputStream s)

/**
* Reconstitutes this task from a stream (that is, deserializes it).
* @param s the stream
* @throws ClassNotFoundException if the class of a serialized object
* could not be found
* @throws java.io.IOException if an I/O error occurs
*/
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/jsr166e/RecursiveTask.java
Expand Up @@ -15,7 +15,7 @@
* class Fibonacci extends RecursiveTask<Integer> {
* final int n;
* Fibonacci(int n) { this.n = n; }
* Integer compute() {
* protected Integer compute() {
* if (n <= 1)
* return n;
* Fibonacci f1 = new Fibonacci(n - 1);
Expand Down Expand Up @@ -46,6 +46,7 @@ public abstract class RecursiveTask<V> extends ForkJoinTask<V> {

/**
* The main computation performed by this task.
* @return the result of the computation
*/
protected abstract V compute();

Expand Down

0 comments on commit 80ab75e

Please sign in to comment.