Some cleanup to make it more readable (#10586)

Motivation:

some cleanup to make it more readable

Modifications:

- fix typos
- remove cqe kRingMask
- remove unused pendingWakeup

Result:

cleaner code
This commit is contained in:
Josef Grieb 2020-09-23 09:55:51 +02:00 committed by GitHub
parent 11ef990f05
commit 0421c9c751
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 20 deletions

View File

@ -714,10 +714,14 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha
} }
@Override @Override
protected void doDeregister() throws Exception { protected void doDeregister() {
IOUringSubmissionQueue submissionQueue = submissionQueue(); IOUringSubmissionQueue submissionQueue = submissionQueue();
if (submissionQueue != null) { if (submissionQueue != null) {
if ((ioState & (POLL_IN_SCHEDULED | POLL_OUT_SCHEDULED | POLL_RDHUP_SCHEDULED)) == 0) {
((IOUringEventLoop) eventLoop()).remove(this);
return;
}
if ((ioState & POLL_IN_SCHEDULED) != 0) { if ((ioState & POLL_IN_SCHEDULED) != 0) {
submissionQueue.addPollRemove(socket.intValue(), Native.POLLIN); submissionQueue.addPollRemove(socket.intValue(), Native.POLLIN);
} }

View File

@ -33,8 +33,8 @@ final class IOUringCompletionQueue {
//these unsigned integer pointers(shared with the kernel) will be changed by the kernel //these unsigned integer pointers(shared with the kernel) will be changed by the kernel
private final long kHeadAddress; private final long kHeadAddress;
private final long kTailAddress; private final long kTailAddress;
private final long kringMaskAddress; private final long kRingMaskAddress;
private final long kringEntries; private final long kRingEntriesAddress;
private final long kOverflowAddress; private final long kOverflowAddress;
private final long completionQueueArrayAddress; private final long completionQueueArrayAddress;
@ -46,20 +46,20 @@ final class IOUringCompletionQueue {
private final int ringMask; private final int ringMask;
private int ringHead; private int ringHead;
IOUringCompletionQueue(long kHeadAddress, long kTailAddress, long kringMaskAddress, long kringEntries, IOUringCompletionQueue(long kHeadAddress, long kTailAddress, long kRingMaskAddress, long kRingEntriesAddress,
long kOverflowAddress, long completionQueueArrayAddress, int ringSize, long ringAddress, long kOverflowAddress, long completionQueueArrayAddress, int ringSize, long ringAddress,
int ringFd) { int ringFd) {
this.kHeadAddress = kHeadAddress; this.kHeadAddress = kHeadAddress;
this.kTailAddress = kTailAddress; this.kTailAddress = kTailAddress;
this.kringMaskAddress = kringMaskAddress; this.kRingMaskAddress = kRingMaskAddress;
this.kringEntries = kringEntries; this.kRingEntriesAddress = kRingEntriesAddress;
this.kOverflowAddress = kOverflowAddress; this.kOverflowAddress = kOverflowAddress;
this.completionQueueArrayAddress = completionQueueArrayAddress; this.completionQueueArrayAddress = completionQueueArrayAddress;
this.ringSize = ringSize; this.ringSize = ringSize;
this.ringAddress = ringAddress; this.ringAddress = ringAddress;
this.ringFd = ringFd; this.ringFd = ringFd;
this.ringMask = PlatformDependent.getIntVolatile(kringMaskAddress); this.ringMask = PlatformDependent.getIntVolatile(kRingMaskAddress);
this.ringHead = PlatformDependent.getIntVolatile(kHeadAddress); this.ringHead = PlatformDependent.getIntVolatile(kHeadAddress);
} }

View File

@ -57,7 +57,6 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
private final byte[] inet6AddressArray = new byte[16]; private final byte[] inet6AddressArray = new byte[16];
private long prevDeadlineNanos = NONE; private long prevDeadlineNanos = NONE;
private boolean pendingWakeup;
IOUringEventLoop(IOUringEventLoopGroup parent, Executor executor, int ringSize, boolean ioseqAsync, IOUringEventLoop(IOUringEventLoopGroup parent, Executor executor, int ringSize, boolean ioseqAsync,
RejectedExecutionHandler rejectedExecutionHandler, EventLoopTaskQueueFactory queueFactory) { RejectedExecutionHandler rejectedExecutionHandler, EventLoopTaskQueueFactory queueFactory) {
@ -168,9 +167,7 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
} }
} }
} finally { } finally {
if (nextWakeupNanos.get() == AWAKE || nextWakeupNanos.getAndSet(AWAKE) == AWAKE) { nextWakeupNanos.set(AWAKE);
pendingWakeup = true;
}
} }
} catch (Throwable t) { } catch (Throwable t) {
handleLoopException(t); handleLoopException(t);
@ -224,7 +221,6 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
public void handle(int fd, int res, int flags, int op, int data) { public void handle(int fd, int res, int flags, int op, int data) {
if (op == Native.IORING_OP_READ && eventfd.intValue() == fd) { if (op == Native.IORING_OP_READ && eventfd.intValue() == fd) {
if (res != Native.ERRNO_ECANCELED_NEGATIVE) { if (res != Native.ERRNO_ECANCELED_NEGATIVE) {
pendingWakeup = false;
addEventFdRead(ringBuffer.ioUringSubmissionQueue()); addEventFdRead(ringBuffer.ioUringSubmissionQueue());
} }
} else if (op == Native.IORING_OP_TIMEOUT) { } else if (op == Native.IORING_OP_TIMEOUT) {
@ -251,7 +247,7 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
} }
if (!channel.ioScheduled()) { if (!channel.ioScheduled()) {
// We cancelled the POLL ops which means we are done and should remove the mapping. // We cancelled the POLL ops which means we are done and should remove the mapping.
channels.remove(fd); remove(channel);
return; return;
} }
} else if (op == Native.IORING_OP_CONNECT) { } else if (op == Native.IORING_OP_CONNECT) {

View File

@ -48,9 +48,9 @@ final class IOUringSubmissionQueue {
//these unsigned integer pointers(shared with the kernel) will be changed by the kernel //these unsigned integer pointers(shared with the kernel) will be changed by the kernel
private final long kHeadAddress; private final long kHeadAddress;
private final long kTailAddress; private final long kTailAddress;
private final long fFlagsAdress; private final long kFlagsAddress;
private final long kDroppedAddress; private final long kDroppedAddress;
private final long arrayAddress; private final long kArrayAddress;
final long submissionQueueArrayAddress; final long submissionQueueArrayAddress;
final int ringEntries; final int ringEntries;
@ -66,14 +66,14 @@ final class IOUringSubmissionQueue {
private int tail; private int tail;
IOUringSubmissionQueue(long kHeadAddress, long kTailAddress, long kRingMaskAddress, long kRingEntriesAddress, IOUringSubmissionQueue(long kHeadAddress, long kTailAddress, long kRingMaskAddress, long kRingEntriesAddress,
long fFlagsAdress, long kDroppedAddress, long arrayAddress, long submissionQueueArrayAddress, long kFlagsAddress, long kDroppedAddress, long kArrayAddress,
int ringSize, long ringAddress, int ringFd, long submissionQueueArrayAddress, int ringSize, long ringAddress, int ringFd,
boolean iosqeAsync, Runnable submissionCallback) { boolean iosqeAsync, Runnable submissionCallback) {
this.kHeadAddress = kHeadAddress; this.kHeadAddress = kHeadAddress;
this.kTailAddress = kTailAddress; this.kTailAddress = kTailAddress;
this.fFlagsAdress = fFlagsAdress; this.kFlagsAddress = kFlagsAddress;
this.kDroppedAddress = kDroppedAddress; this.kDroppedAddress = kDroppedAddress;
this.arrayAddress = arrayAddress; this.kArrayAddress = kArrayAddress;
this.submissionQueueArrayAddress = submissionQueueArrayAddress; this.submissionQueueArrayAddress = submissionQueueArrayAddress;
this.ringSize = ringSize; this.ringSize = ringSize;
this.ringAddress = ringAddress; this.ringAddress = ringAddress;
@ -90,7 +90,7 @@ final class IOUringSubmissionQueue {
PlatformDependent.setMemory(submissionQueueArrayAddress, ringEntries * SQE_SIZE, (byte) 0); PlatformDependent.setMemory(submissionQueueArrayAddress, ringEntries * SQE_SIZE, (byte) 0);
// Fill SQ array indices (1-1 with SQE array) and set nonzero constant SQE fields // Fill SQ array indices (1-1 with SQE array) and set nonzero constant SQE fields
long address = arrayAddress; long address = kArrayAddress;
long sqeFlagsAddress = submissionQueueArrayAddress + SQE_FLAGS_FIELD; long sqeFlagsAddress = submissionQueueArrayAddress + SQE_FLAGS_FIELD;
byte flag = iosqeAsync ? (byte) Native.IOSQE_ASYNC : 0; byte flag = iosqeAsync ? (byte) Native.IOSQE_ASYNC : 0;
for (int i = 0; i < ringEntries; i++, address += INT_SIZE, sqeFlagsAddress += SQE_SIZE) { for (int i = 0; i < ringEntries; i++, address += INT_SIZE, sqeFlagsAddress += SQE_SIZE) {