Skip to content

Commit ac4dfb2

Browse files
committed
Minor cleanup
1 parent ae9f7e2 commit ac4dfb2

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

java-does-usb/src/main/java/net/codecrete/usb/linux/EPoll.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import java.lang.foreign.MemoryLayout;
1717
import java.lang.foreign.MemorySegment;
1818
import java.lang.foreign.SequenceLayout;
19-
import java.lang.foreign.MemoryLayout.PathElement;
20-
import java.lang.foreign.ValueLayout.OfInt;
2119
import java.lang.invoke.MethodHandle;
2220
import java.lang.invoke.VarHandle;
2321

@@ -31,7 +29,7 @@
3129
import static net.codecrete.usb.linux.gen.epoll.epoll.EPOLL_CTL_ADD;
3230
import static net.codecrete.usb.linux.gen.epoll.epoll.EPOLL_CTL_DEL;
3331

34-
@SuppressWarnings({"OptionalGetWithoutIsPresent", "SameParameterValue", "java:S100"})
32+
@SuppressWarnings({"OptionalGetWithoutIsPresent", "SameParameterValue", "java:S100", "java:S1192"})
3533
public class EPoll {
3634
private EPoll() {}
3735

@@ -64,16 +62,14 @@ private EPoll() {}
6462
);
6563

6664
// varhandle to access the "fd" field in an epoll_event struct
67-
static final VarHandle EVENT_DATA_FD$VH = EVENT$LAYOUT.varHandle(
65+
private static final VarHandle EVENT_DATA_FD$VH = EVENT$LAYOUT.varHandle(
6866
MemoryLayout.PathElement.groupElement("data"),
6967
MemoryLayout.PathElement.groupElement("fd")
7068
);
7169

72-
private static final OfInt EVENT_EVENTS$LAYOUT = (OfInt)EVENT$LAYOUT.select(PathElement.groupElement("events"));
73-
74-
private static void event_events(MemorySegment struct, int fieldValue) {
75-
struct.set(EVENT_EVENTS$LAYOUT, 0, fieldValue);
76-
}
70+
private static final VarHandle EVENTS$VH = EVENT$LAYOUT.varHandle(
71+
MemoryLayout.PathElement.groupElement("events")
72+
);
7773

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

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

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

133129
var event = arena.allocate(EVENT$LAYOUT);
134-
event_events(event, 0);
130+
EVENTS$VH.set(event, 0, 0);
135131
EVENT_DATA_FD$VH.set(event, 0, fd);
136132
var ret = epoll_ctl(epfd, EPOLL_CTL_DEL(), fd, event, errorState);
137133
if (ret < 0) {

java-does-usb/src/main/java/net/codecrete/usb/macos/MacosAsyncTask.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
import java.util.concurrent.locks.ReentrantLock;
2424

2525
import static java.lang.foreign.MemorySegment.NULL;
26-
import static java.lang.foreign.ValueLayout.*;
26+
import static java.lang.foreign.ValueLayout.ADDRESS;
27+
import static java.lang.foreign.ValueLayout.JAVA_INT;
28+
import static java.lang.foreign.ValueLayout.JAVA_LONG;
29+
import static java.lang.foreign.ValueLayout.JAVA_LONG_UNALIGNED;
2730

2831

2932
/**

0 commit comments

Comments
 (0)