Skip to content

Commit 36d5657

Browse files
authored
Merge pull request #78 from OpenHFT/jna_5_8_0
compatibility with JNA 5.8.0. Fixes #77
2 parents af951fd + 7a264a8 commit 36d5657

File tree

10 files changed

+20
-907
lines changed

10 files changed

+20
-907
lines changed

affinity/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
</build>
129129
</profile>
130130
</profiles>
131+
131132
<build>
132133
<plugins>
133134
<plugin>

affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static int syscall(int number, Object... args) {
158158
}
159159

160160
interface CLibrary extends Library {
161-
CLibrary INSTANCE = (CLibrary) Native.loadLibrary(LIBRARY_NAME, CLibrary.class);
161+
CLibrary INSTANCE = Native.load(LIBRARY_NAME, CLibrary.class);
162162

163163
int sched_setaffinity(final int pid,
164164
final int cpusetsize,

affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public int getThreadId() {
7272
}
7373

7474
interface CLibrary extends Library {
75-
CLibrary INSTANCE = (CLibrary)
76-
Native.loadLibrary("libpthread.dylib", CLibrary.class);
75+
CLibrary INSTANCE = Native.load("libpthread.dylib", CLibrary.class);
7776

7877
int pthread_self() throws LastErrorException;
7978
}

affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ public int getThreadId() {
191191
* @author BegemoT
192192
*/
193193
interface CLibrary extends Library {
194-
CLibrary INSTANCE = (CLibrary)
195-
Native.loadLibrary(LIBRARY_NAME, CLibrary.class);
194+
CLibrary INSTANCE = Native.load(LIBRARY_NAME, CLibrary.class);
196195

197196
int sched_setaffinity(final int pid,
198197
final int cpusetsize,

affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public int getThreadId() {
7272
}
7373

7474
interface CLibrary extends Library {
75-
CLibrary INSTANCE = (CLibrary)
76-
Native.loadLibrary("c", CLibrary.class);
75+
CLibrary INSTANCE = Native.load("c", CLibrary.class);
7776

7877
int pthread_self() throws LastErrorException;
7978
}

affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717

1818
package net.openhft.affinity.impl;
1919

20-
import com.sun.jna.LastErrorException;
21-
import com.sun.jna.Library;
22-
import com.sun.jna.Native;
23-
import com.sun.jna.PointerType;
20+
import com.sun.jna.*;
2421
import com.sun.jna.platform.win32.Kernel32;
2522
import com.sun.jna.platform.win32.WinDef;
23+
import com.sun.jna.platform.win32.WinNT;
2624
import com.sun.jna.ptr.LongByReference;
2725
import net.openhft.affinity.IAffinity;
2826
import org.jetbrains.annotations.Nullable;
@@ -86,7 +84,7 @@ public void setAffinity(final BitSet affinity) {
8684

8785
int pid = getTid();
8886
try {
89-
lib.SetThreadAffinityMask(pid, aff);
87+
lib.SetThreadAffinityMask(handle(pid), aff);
9088
} catch (LastErrorException e) {
9189
throw new IllegalStateException("SetThreadAffinityMask((" + pid + ") , &(" + affinity + ") ) errorNo=" + e.getErrorCode(), e);
9290
}
@@ -104,7 +102,7 @@ private BitSet getAffinity0() {
104102
final LongByReference cpuset2 = new LongByReference(0);
105103
try {
106104

107-
final int ret = lib.GetProcessAffinityMask(-1, cpuset1, cpuset2);
105+
final int ret = lib.GetProcessAffinityMask(handle(-1), cpuset1, cpuset2);
108106
// Successful result is positive, according to the docs
109107
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms683213%28v=vs.85%29.aspx
110108
if (ret <= 0) {
@@ -120,6 +118,10 @@ private BitSet getAffinity0() {
120118
return null;
121119
}
122120

121+
private WinNT.HANDLE handle(int pid) {
122+
return new WinNT.HANDLE(new Pointer(pid));
123+
}
124+
123125
public int getTid() {
124126
final CLibrary lib = CLibrary.INSTANCE;
125127

@@ -152,11 +154,11 @@ public int getThreadId() {
152154
* @author BegemoT
153155
*/
154156
private interface CLibrary extends Library {
155-
CLibrary INSTANCE = (CLibrary) Native.loadLibrary("kernel32", CLibrary.class);
157+
CLibrary INSTANCE = Native.load("kernel32", CLibrary.class);
156158

157-
int GetProcessAffinityMask(final int pid, final PointerType lpProcessAffinityMask, final PointerType lpSystemAffinityMask) throws LastErrorException;
159+
int GetProcessAffinityMask(final WinNT.HANDLE pid, final PointerType lpProcessAffinityMask, final PointerType lpSystemAffinityMask) throws LastErrorException;
158160

159-
void SetThreadAffinityMask(final int pid, final WinDef.DWORD lpProcessAffinityMask) throws LastErrorException;
161+
void SetThreadAffinityMask(final WinNT.HANDLE pid, final WinDef.DWORD lpProcessAffinityMask) throws LastErrorException;
160162

161163
int GetCurrentThread() throws LastErrorException;
162164
}

affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package net.openhft.affinity.impl;
1919

20-
import net.openhft.affinity.AffinitySupport;
20+
import net.openhft.affinity.Affinity;
2121
import net.openhft.affinity.IAffinity;
2222
import org.junit.Assume;
2323
import org.junit.BeforeClass;
@@ -45,7 +45,7 @@ public IAffinity getImpl() {
4545
public void testGettid() {
4646
System.out.println("pid=" + getImpl().getProcessId());
4747
System.out.println("tid=" + getImpl().getThreadId());
48-
AffinitySupport.setThreadId();
48+
Affinity.setThreadId();
4949

5050
for (int j = 0; j < 3; j++) {
5151
final int runs = 100000;

affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package net.openhft.affinity.impl;
1919

2020
import net.openhft.affinity.Affinity;
21-
import net.openhft.affinity.AffinitySupport;
2221
import net.openhft.affinity.IAffinity;
2322
import org.junit.Assume;
2423
import org.junit.BeforeClass;
@@ -44,7 +43,7 @@ public IAffinity getImpl() {
4443
public void testGettid() {
4544
System.out.println("pid=" + getImpl().getProcessId());
4645
System.out.println("tid=" + getImpl().getThreadId());
47-
AffinitySupport.setThreadId();
46+
Affinity.setThreadId();
4847

4948
for (int j = 0; j < 3; j++) {
5049
final int runs = 100000;

affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.io.IOException;
2323
import java.io.InputStream;
2424

25-
import static junit.framework.Assert.assertEquals;
25+
import static org.junit.Assert.assertEquals;
2626

2727
/**
2828
* @author peter.lawrey

0 commit comments

Comments
 (0)