public class Test {
public static void main(String[] args) throws InterruptedException {
TestLib lib = Native.loadLibrary("hello", TestLib.class);
for (int i = 0; i < 10; i++) {
lib.registerCallback(new TestCallback());
}
new Thread(() -> {
while (true) {
try {
System.out.println("-------------------" + TestCallback.i.getAndSet(0) + " === " );
lib.printInfo();
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
for (int i = 1; i <= 32; i++) {
new Thread(() -> lib.start()).start();
}
}
public static class TestCallback implements Callback {
static AtomicLong i = new AtomicLong(0);
public void callback(ArrayStruct hdrs) {
i.addAndGet(hdrs.size);
}
}
public static class ArrayStruct extends Structure {
public int size;
public TestStruct.ByReference list;
public ArrayStruct() {
}
public ArrayStruct(Pointer peer) {
super(peer);
read();
}
@Override
protected List<String> getFieldOrder() {
return Arrays.asList("size", "list");
}
}
public static class TestStruct extends Structure {
public String strField;
public int intField;
public String getStrField() {
return strField;
}
public void setStrField(String strField) {
this.strField = strField;
}
public TestStruct() {
}
public TestStruct(Pointer peer) {
super(peer);
read();
}
public int getIntField() {
return intField;
}
public void setIntField(int intField) {
this.intField = intField;
}
@Override
protected List<String> getFieldOrder() {
return Arrays.asList("strField", "intField");
}
public static class ByReference extends TestStruct implements Structure.ByReference {}
}
}
.slide { transition: all .2s ease-in-out; }
.slide.active { transform: scale(1.1); }