Skip to content

Commit bce3da0

Browse files
committed
Remove dependency from shaded JCTools
1 parent 005213f commit bce3da0

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

core/src/main/java/io/netty/loom/MpscUnboundedStream.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.netty.loom;
22

3-
import io.netty.util.internal.shaded.org.jctools.util.Pow2;
4-
53
import java.lang.invoke.MethodHandles;
64
import java.lang.invoke.VarHandle;
75

@@ -73,7 +71,7 @@ public MpscUnboundedStream(int initialCapacity) {
7371
if (initialCapacity < 2) {
7472
throw new IllegalArgumentException("Initial capacity must be 2 or more");
7573
}
76-
int p2capacity = Pow2.roundToPowerOfTwo(initialCapacity);
74+
int p2capacity = roundToPowerOfTwo(initialCapacity);
7775
// leave lower bit of mask clear
7876
long mask = (p2capacity - 1) << 1;
7977
// need extra element to point at next array
@@ -86,6 +84,18 @@ public MpscUnboundedStream(int initialCapacity) {
8684
soProducerLimit(mask); // we know it's all empty to start with
8785
}
8886

87+
private static int roundToPowerOfTwo(final int value) {
88+
if (value > 1 << 30) {
89+
throw new IllegalArgumentException(
90+
"There is no larger power of 2 int for value:" + value + " since it exceeds 2^31.");
91+
}
92+
if (value < 0) {
93+
throw new IllegalArgumentException("Given value:" + value + ". Expecting value >= 0.");
94+
}
95+
final int nextPow2 = 1 << (32 - Integer.numberOfLeadingZeros(value - 1));
96+
return nextPow2;
97+
}
98+
8999
private void soProducerLimit(long v) {
90100
PRODUCER_LIMIT.setRelease(this, v);
91101
}

0 commit comments

Comments
 (0)