1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.uring;
17
18 import io.netty.util.internal.ObjectUtil;
19
20 import java.util.Objects;
21
22
23
24
25
26 public final class IoUringBufferRingConfig {
27 private final short bgId;
28 private final short bufferRingSize;
29 private final int maxUnreleasedBuffers;
30 private final boolean incremental;
31 private final IoUringBufferRingAllocator allocator;
32
33
34
35
36
37
38
39
40
41
42
43
44 public IoUringBufferRingConfig(short bgId, short bufferRingSize, int maxUnreleasedBuffers,
45 IoUringBufferRingAllocator allocator) {
46 this(bgId, bufferRingSize, maxUnreleasedBuffers, IoUring.isRegisterBufferRingIncSupported(), allocator);
47 }
48
49
50
51
52
53
54
55
56
57
58
59
60
61 public IoUringBufferRingConfig(short bgId, short bufferRingSize, int maxUnreleasedBuffers,
62 boolean incremental, IoUringBufferRingAllocator allocator) {
63 this.bgId = (short) ObjectUtil.checkPositiveOrZero(bgId, "bgId");
64 this.bufferRingSize = checkBufferRingSize(bufferRingSize);
65 this.maxUnreleasedBuffers = ObjectUtil.checkInRange(
66 maxUnreleasedBuffers, bufferRingSize, Integer.MAX_VALUE, "maxUnreleasedBuffers");
67 if (incremental && !IoUring.isRegisterBufferRingIncSupported()) {
68 throw new IllegalArgumentException("Incremental buffer ring is not supported");
69 }
70 this.incremental = incremental;
71 this.allocator = ObjectUtil.checkNotNull(allocator, "allocator");
72 }
73
74
75
76
77
78
79 public short bufferGroupId() {
80 return bgId;
81 }
82
83
84
85
86
87
88 public short bufferRingSize() {
89 return bufferRingSize;
90 }
91
92
93
94
95
96
97
98 public int maxUnreleasedBuffers() {
99 return maxUnreleasedBuffers;
100 }
101
102
103
104
105
106
107 public IoUringBufferRingAllocator allocator() {
108 return allocator;
109 }
110
111
112
113
114
115
116
117
118 public boolean isIncremental() {
119 return incremental;
120 }
121
122 private static short checkBufferRingSize(short bufferRingSize) {
123 if (bufferRingSize < 1) {
124 throw new IllegalArgumentException("bufferRingSize: " + bufferRingSize + " (expected: > 0)");
125 }
126
127 boolean isPowerOfTwo = (bufferRingSize & (bufferRingSize - 1)) == 0;
128 if (!isPowerOfTwo) {
129 throw new IllegalArgumentException("bufferRingSize: " + bufferRingSize + " (expected: power of 2)");
130 }
131 return bufferRingSize;
132 }
133
134 @Override
135 public boolean equals(Object o) {
136 if (o == null || getClass() != o.getClass()) {
137 return false;
138 }
139 IoUringBufferRingConfig that = (IoUringBufferRingConfig) o;
140 return bgId == that.bgId;
141 }
142
143 @Override
144 public int hashCode() {
145 return Objects.hashCode(bgId);
146 }
147 }