aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2015-09-23 15:18:01 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2015-09-24 14:16:42 +0000
commit504529b470857bec392cf58cf7c6b16dd6df0521 (patch)
tree7ba665931a2f051e108295731e43adbb9c85573b /src
parent95f624f4170f170854af185dfc336bb80fa9e470 (diff)
Move callUninterruptibly to a helper class in lib.concurrent.
-- MOS_MIGRATED_REVID=103747062
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/concurrent/Uninterruptibles.java47
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java28
3 files changed, 51 insertions, 27 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/concurrent/Uninterruptibles.java b/src/main/java/com/google/devtools/build/lib/concurrent/Uninterruptibles.java
new file mode 100644
index 0000000000..dff9323d49
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/concurrent/Uninterruptibles.java
@@ -0,0 +1,47 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.concurrent;
+
+import java.util.concurrent.Callable;
+
+/**
+ * Helper class for dealing with {@link InterruptedException}.
+ */
+public final class Uninterruptibles {
+
+ /**
+ * Calls the given callable uninterruptibly.
+ *
+ * <p>If the callable throws {@link InterruptedException}, calls it again, until the callable
+ * returns a result. Sets the {@code currentThread().interrupted()} bit if the callable threw
+ * {@link InterruptedException} at least once.
+ */
+ public static final <T> T callUninterruptibly(Callable<T> callable) throws Exception {
+ boolean interrupted = false;
+ try {
+ while (true) {
+ try {
+ return callable.call();
+ } catch (InterruptedException e) {
+ interrupted = true;
+ }
+ }
+ } finally {
+ if (interrupted) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+}
+
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
index 9f677143aa..c186d19716 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
@@ -33,6 +33,7 @@ import com.google.devtools.build.lib.analysis.WorkspaceStatusAction.Factory;
import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory;
import com.google.devtools.build.lib.analysis.config.BinTools;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
+import com.google.devtools.build.lib.concurrent.Uninterruptibles;
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.packages.PackageFactory;
@@ -533,7 +534,7 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor {
// Run the invalidator to actually delete the values.
try {
progressReceiver.ignoreInvalidations = true;
- callUninterruptibly(new Callable<Void>() {
+ Uninterruptibles.callUninterruptibly(new Callable<Void>() {
@Override
public Void call() throws InterruptedException {
buildDriver.evaluate(ImmutableList.<SkyKey>of(), false,
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index bc624d1837..8e74239d05 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -13,6 +13,8 @@
// limitations under the License.
package com.google.devtools.build.lib.skyframe;
+import static com.google.devtools.build.lib.concurrent.Uninterruptibles.callUninterruptibly;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
@@ -1533,32 +1535,6 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory {
}
}
- /**
- * Calls the given callable uninterruptibly.
- *
- * <p>If the callable throws {@link InterruptedException}, calls it again, until the callable
- * returns a result. Sets the {@code currentThread().interrupted()} bit if the callable threw
- * {@link InterruptedException} at least once.
- *
- * <p>This is almost identical to {@code Uninterruptibles#getUninterruptibly}.
- */
- protected static final <T> T callUninterruptibly(Callable<T> callable) throws Exception {
- boolean interrupted = false;
- try {
- while (true) {
- try {
- return callable.call();
- } catch (InterruptedException e) {
- interrupted = true;
- }
- }
- } finally {
- if (interrupted) {
- Thread.currentThread().interrupt();
- }
- }
- }
-
@VisibleForTesting
public MemoizingEvaluator getEvaluatorForTesting() {
return memoizingEvaluator;