Skip to content

Commit 18d18fa

Browse files
authored
Merge pull request OpenHFT#50 from mprusakov/patch-2
Allow thread pinning by pid
2 parents e0987f6 + b9e4a40 commit 18d18fa

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ cpu_set_t sched_getaffinity() {
6666
return cpuset;
6767
}
6868

69-
public static void sched_setaffinity(final BitSet affinity) {
69+
public static void sched_setaffinity(final BitSet affinity) {
70+
sched_setaffinity(0, affinity);
71+
}
72+
73+
public static void sched_setaffinity(final int pid, final BitSet affinity) {
7074
final CLibrary lib = CLibrary.INSTANCE;
7175
final cpu_set_t cpuset = new cpu_set_t();
7276
final int size = version.isSameOrNewer(VERSION_2_6) ? cpu_set_t.SIZE_OF_CPU_SET_T : NativeLong.SIZE;
@@ -80,12 +84,12 @@ public static void sched_setaffinity(final BitSet affinity) {
8084
}
8185
}
8286
try {
83-
if (lib.sched_setaffinity(0, size, cpuset) != 0) {
84-
throw new IllegalStateException("sched_setaffinity(0, " + size +
87+
if (lib.sched_setaffinity(pid, size, cpuset) != 0) {
88+
throw new IllegalStateException("sched_setaffinity(" + pid + ", " + size +
8589
", 0x" + Utilities.toHexString(affinity) + ") failed; errno=" + Native.getLastError());
8690
}
8791
} catch (LastErrorException e) {
88-
throw new IllegalStateException("sched_setaffinity(0, " + size +
92+
throw new IllegalStateException("sched_setaffinity(" + pid + ", " + size +
8993
", 0x" + Utilities.toHexString(affinity) + ") failed; errno=" + e.getErrorCode(), e);
9094
}
9195
}

0 commit comments

Comments
 (0)