Skip to content

Commit 4e3dad4

Browse files
author
Stefania Alborghetti
committed
Nits
1 parent babb36e commit 4e3dad4

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

transport-native-epoll/src/main/java/io/netty/channel/epoll/AIOContext.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class AIOContext {
3434
private final long address;
3535
private long nextId;
3636
private long outstanding;
37-
private long maxOutstanding;
37+
private final long maxOutstanding;
3838
private final Map<Long, IORequest> outstandingRequests;
3939
private final ArrayDeque<IORequest> pendingRequests;
4040
private volatile boolean destroyed;
@@ -70,7 +70,8 @@ public <A> void read(final AIOEpollFileChannel file, final ByteBuffer dst, final
7070
assert !destroyed;
7171
assert dst.isDirect();
7272
assert dst.position() == 0;
73-
assert file.epollEventLoop.aioContext == this;
73+
74+
file.verify(this);
7475

7576
int length = (dst.limit() & 511) == 0 ? dst.limit() : ((dst.limit() + 511) & ~511);
7677
if (dst.capacity() < length) {
@@ -88,7 +89,7 @@ public <A> void read(final AIOEpollFileChannel file, final ByteBuffer dst, final
8889
IORequest<A> request = new IORequest<A>(file, dst, position, length, handler, attachment);
8990

9091
try {
91-
// Avoid sending overflowing the aio context queue (EGAIN)
92+
// Avoid sending overflowing the aio context queue (EAGAIN)
9293
// instead buffer locally
9394
if (outstanding + 1 <= maxOutstanding) {
9495
long id = Native.submitAIORead(this, file.getEventFd(), file.getFd(), position, length, dst);
@@ -117,7 +118,8 @@ public <A> void read(final AIOEpollFileChannel file, final ByteBuffer dst, final
117118

118119
public void processReady(AIOEpollFileChannel file) {
119120
assert !destroyed;
120-
assert file.epollEventLoop.aioContext == this;
121+
file.verify(this);
122+
121123
IORequest request = null;
122124
try {
123125
long numReady = Native.eventFdRead(file.getEventFd());
@@ -156,7 +158,7 @@ public void processReady(AIOEpollFileChannel file) {
156158
// Push any pending requests if we have room
157159
try {
158160
if (outstanding + 1 <= maxOutstanding && (req = pendingRequests.poll()) != null) {
159-
assert req.file.epollEventLoop.aioContext == this;
161+
req.file.verify(this);
160162
long nextId = Native.submitAIORead(this, req.file.getEventFd(), req.file.getFd(),
161163
req.position, req.length, req.buffer);
162164
IORequest r = outstandingRequests.putIfAbsent(nextId, req);

transport-native-epoll/src/main/java/io/netty/channel/epoll/AIOEpollFileChannel.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import io.netty.channel.unix.FileDescriptor;
3131
import io.netty.util.internal.logging.InternalLogger;
3232
import io.netty.util.internal.logging.InternalLoggerFactory;
33-
import org.jctools.queues.SpscGrowableArrayQueue;
3433

3534

3635
public class AIOEpollFileChannel extends AsynchronousFileChannel {
@@ -39,7 +38,7 @@ public class AIOEpollFileChannel extends AsynchronousFileChannel {
3938
private final File fileObject;
4039
private final FileDescriptor file;
4140
private final FileDescriptor eventFd;
42-
final EpollEventLoop epollEventLoop;
41+
private final EpollEventLoop epollEventLoop;
4342
private final EventFileChannel nettyChannel;
4443
private final boolean isDirect;
4544

@@ -72,6 +71,15 @@ public void run() {
7271
}
7372
}
7473

74+
/**
75+
* Called by {@link AIOContext} to verify it has received a file with the same context as itself.
76+
*
77+
* @param context - the context calling this method
78+
*/
79+
void verify(AIOContext context) {
80+
assert epollEventLoop.aioContext == context : "Wrong AIO context tried to access file channel";
81+
}
82+
7583
public int getEventFd() {
7684
return eventFd.intValue();
7785
}

transport-native-epoll/src/test/java/io/netty/channel/epoll/LibAIOTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,23 @@ public void run() {
144144
int idx = 0;
145145
try {
146146
final EpollEventLoop loop = loops[tid % 8];
147+
final int numIterations = 1024;
147148

148149
AsynchronousFileChannel fc = new AIOEpollFileChannel(file, loop, FileDescriptor.O_RDONLY |
149150
FileDescriptor.O_DIRECT);
150151
List<ImmutablePair<ByteBuffer, Future<Integer>>> futures =
151-
new ArrayList<ImmutablePair<ByteBuffer, Future<Integer>>>();
152+
new ArrayList<ImmutablePair<ByteBuffer, Future<Integer>>>(numIterations);
152153

153-
for (int i = 0; i < 1024; i++) {
154+
for (int i = 0; i < numIterations; i++) {
154155
//System.err.println(loop.threadProperties().name());
155156
ByteBuffer buf = allocateAlignedByteBuffer(LEN, 512);
156157

157-
buf.clear();
158158
futures.add(new ImmutablePair<ByteBuffer,
159159
Future<Integer>>(buf, fc.read(buf,
160160
value.length() * (i % 1024))));
161161
}
162162

163-
for (int i = 0; i < 1024; i++) {
163+
for (int i = 0; i < numIterations; i++) {
164164
int len = futures.get(i).getRight().get();
165165
ByteBuffer buf = futures.get(i).getLeft();
166166
buf.flip();

0 commit comments

Comments
 (0)