Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbl committed Mar 16, 2024
1 parent ae9f7e2 commit ac4dfb2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
18 changes: 7 additions & 11 deletions java-does-usb/src/main/java/net/codecrete/usb/linux/EPoll.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SequenceLayout;
import java.lang.foreign.MemoryLayout.PathElement;
import java.lang.foreign.ValueLayout.OfInt;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;

Expand All @@ -31,7 +29,7 @@
import static net.codecrete.usb.linux.gen.epoll.epoll.EPOLL_CTL_ADD;
import static net.codecrete.usb.linux.gen.epoll.epoll.EPOLL_CTL_DEL;

@SuppressWarnings({"OptionalGetWithoutIsPresent", "SameParameterValue", "java:S100"})
@SuppressWarnings({"OptionalGetWithoutIsPresent", "SameParameterValue", "java:S100", "java:S1192"})
public class EPoll {
private EPoll() {}

Expand Down Expand Up @@ -64,16 +62,14 @@ private EPoll() {}
);

// varhandle to access the "fd" field in an epoll_event struct
static final VarHandle EVENT_DATA_FD$VH = EVENT$LAYOUT.varHandle(
private static final VarHandle EVENT_DATA_FD$VH = EVENT$LAYOUT.varHandle(
MemoryLayout.PathElement.groupElement("data"),
MemoryLayout.PathElement.groupElement("fd")
);

private static final OfInt EVENT_EVENTS$LAYOUT = (OfInt)EVENT$LAYOUT.select(PathElement.groupElement("events"));

private static void event_events(MemorySegment struct, int fieldValue) {
struct.set(EVENT_EVENTS$LAYOUT, 0, fieldValue);
}
private static final VarHandle EVENTS$VH = EVENT$LAYOUT.varHandle(
MemoryLayout.PathElement.groupElement("events")
);

private static final Linker linker = Linker.nativeLinker();

Expand Down Expand Up @@ -118,7 +114,7 @@ static void addFileDescriptor(int epfd, int op, int fd) {
var errorState = allocateErrorState(arena);

var event = arena.allocate(EVENT$LAYOUT);
event_events(event, op);
EVENTS$VH.set(event, 0, op);
EVENT_DATA_FD$VH.set(event, 0, fd);
var ret = epoll_ctl(epfd, EPOLL_CTL_ADD(), fd, event, errorState);
if (ret < 0)
Expand All @@ -131,7 +127,7 @@ static void removeFileDescriptor(int epfd, int fd) {
var errorState = allocateErrorState(arena);

var event = arena.allocate(EVENT$LAYOUT);
event_events(event, 0);
EVENTS$VH.set(event, 0, 0);
EVENT_DATA_FD$VH.set(event, 0, fd);
var ret = epoll_ctl(epfd, EPOLL_CTL_DEL(), fd, event, errorState);
if (ret < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import java.util.concurrent.locks.ReentrantLock;

import static java.lang.foreign.MemorySegment.NULL;
import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.ValueLayout.ADDRESS;
import static java.lang.foreign.ValueLayout.JAVA_INT;
import static java.lang.foreign.ValueLayout.JAVA_LONG;
import static java.lang.foreign.ValueLayout.JAVA_LONG_UNALIGNED;


/**
Expand Down

0 comments on commit ac4dfb2

Please sign in to comment.