File tree Expand file tree Collapse file tree
core/src/main/java/io/netty/loom Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package io .netty .loom ;
22
3- import io .netty .util .internal .shaded .org .jctools .util .Pow2 ;
4-
53import java .lang .invoke .MethodHandles ;
64import 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 }
You can’t perform that action at this time.
0 commit comments