Skip to content

Commit 0638a3a

Browse files
committed
JNA 5.8.0
1 parent af951fd commit 0638a3a

6 files changed

Lines changed: 16 additions & 16 deletions

File tree

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
}

0 commit comments

Comments
 (0)