aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/concurrent
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2016-11-23 20:58:07 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-11-24 10:32:56 +0000
commita16d9f136ff11e8c6b1d5b65f07bb830958b7448 (patch)
tree727bd8f1412bb9f15bc1ad8b2af54aa5dfdb2581 /src/main/java/com/google/devtools/build/lib/concurrent
parent9a56128a43ebac47ced36078e1522f1d94fb3e01 (diff)
Introduce BlazeInterners, a Blaze-specific wrapper around Guava's Interners that makes an appropriate call to Interners.InternerBuilder#concurrencyLevel.
For current readers of this CL, I used this class everywhere in the Blaze codebase. For future readers of this CL, this class should be used to create an Interner in the Blaze codebase. -- MOS_MIGRATED_REVID=140063271
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/concurrent')
-rw-r--r--src/main/java/com/google/devtools/build/lib/concurrent/BlazeInterners.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/concurrent/BlazeInterners.java b/src/main/java/com/google/devtools/build/lib/concurrent/BlazeInterners.java
new file mode 100644
index 0000000000..d54793d8e1
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/concurrent/BlazeInterners.java
@@ -0,0 +1,35 @@
+// Copyright 2016 The Bazel Authors. 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 com.google.common.collect.Interner;
+import com.google.common.collect.Interners;
+import com.google.common.collect.Interners.InternerBuilder;
+
+/** Wrapper around {@link Interners}, with Blaze-specific predetermined concurrency levels. */
+public class BlazeInterners {
+ private static final int CONCURRENCY_LEVEL = Runtime.getRuntime().availableProcessors();
+
+ private static InternerBuilder setConcurrencyLevel(InternerBuilder builder) {
+ return builder.concurrencyLevel(CONCURRENCY_LEVEL);
+ }
+
+ public static <T> Interner<T> newWeakInterner() {
+ return setConcurrencyLevel(Interners.newBuilder().weak()).build();
+ }
+
+ public static <T> Interner<T> newStrongInterner() {
+ return setConcurrencyLevel(Interners.newBuilder().strong()).build();
+ }
+}