aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/concurrent
diff options
context:
space:
mode:
authorGravatar Eric Fellheimer <felly@google.com>2016-03-04 12:53:35 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-03-04 16:16:49 +0000
commitd2bf690b5d69e25945e85e067a9a2a8c2b351d50 (patch)
tree3cb02c8260df18851d35c6c12ae58621c6c718ad /src/main/java/com/google/devtools/build/lib/concurrent
parent37f3e9eeae9b946fe84531582ef366f54b9edd96 (diff)
Allow AbstractQueueVisitor implementations to introspect on active worker count and possibly use that value to make dynamic decisions around scheduling.
-- MOS_MIGRATED_REVID=116351222
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/concurrent')
-rw-r--r--src/main/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitor.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitor.java b/src/main/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitor.java
index 3b7adf6946..22a16e1c27 100644
--- a/src/main/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitor.java
+++ b/src/main/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitor.java
@@ -409,7 +409,7 @@ public class AbstractQueueVisitor implements QuiescingExecutor {
/** Schedules a call. Called in a worker thread if concurrent. */
@Override
public final void execute(Runnable runnable) {
- if (concurrent) {
+ if (runConcurrently()) {
WrappedRunnable wrappedRunnable = new WrappedRunnable(runnable);
try {
// It's impossible for this increment to result in remainingTasks.get <= 0 because
@@ -434,6 +434,22 @@ public class AbstractQueueVisitor implements QuiescingExecutor {
}
}
+ /**
+ * Subclasses may override this to make dynamic decisiouns about whether to run tasks
+ * asynchronously versus in-thread.
+ */
+ protected boolean runConcurrently() {
+ return concurrent;
+ }
+
+ /**
+ * Returns an approximate count of how many threads in the queue visitor's thread pool are
+ * occupied with tasks.
+ */
+ protected final int activeParallelTasks() {
+ return jobs.asMap().size();
+ }
+
protected void executeRunnable(Runnable runnable) {
executorService.execute(runnable);
}