2626public enum JNAAffinity implements AffinitySupport .IAffinity {
2727 INSTANCE ;
2828 public static final Boolean LOADED ;
29- public static final String LIBRARY_NAME = Platform .isWindows () ? "msvcrt" : "c" ;
29+ private static final String LIBRARY_NAME = Platform .isWindows () ? "msvcrt" : "c" ;
3030
3131 /**
3232 * @author BegemoT
33+ * @author jbellis
3334 */
3435 private interface CLibrary extends Library {
3536 public static final CLibrary INSTANCE = (CLibrary )
3637 Native .loadLibrary (LIBRARY_NAME , CLibrary .class );
3738
38- public int sched_setaffinity (final int pid , final int cpusetsize , final PointerType cpuset );
39+ public int sched_setaffinity (final int pid , final int cpusetsize , final PointerType cpuset ) throws LastErrorException ;
3940
40- public int sched_getaffinity (final int pid , final int cpusetsize , final PointerType cpuset );
41+ public int sched_getaffinity (final int pid , final int cpusetsize , final PointerType cpuset ) throws LastErrorException ;
4142
4243// public int sched_getcpu();
4344 }
@@ -58,27 +59,15 @@ public long getAffinity() {
5859 final CLibrary lib = CLibrary .INSTANCE ;
5960 final LongByReference cpuset = new LongByReference (0L );
6061 final int ret = lib .sched_getaffinity (0 , Long .SIZE / 8 , cpuset );
61- if (ret < 0 ) {
62- final int errNo = getErrorNo ();
63- throw new IllegalStateException ("sched_getaffinity((" + Long .SIZE / 8 + ") , &(" + cpuset + ") ) return " + ret + ", errno() = " + errNo );
64- }
62+ assert ret == 0 ;
6563 return cpuset .getValue ();
6664 }
6765
6866 @ Override
6967 public void setAffinity (long affinity ) {
7068 final CLibrary lib = CLibrary .INSTANCE ;
7169 final int ret = lib .sched_setaffinity (0 , Long .SIZE / 8 , new LongByReference (affinity ));
72- if (ret < 0 ) {
73- final int errNo = getErrorNo ();
74- throw new IllegalStateException ("sched_setaffinity((" + Long .SIZE / 8 + ") , &(" + affinity + ") ) return " + ret + ", errno() = " + errNo );
75- }
76- }
77-
78- private static int getErrorNo () {
79- final NativeLibrary nativeLib = NativeLibrary .getInstance (LIBRARY_NAME );
80- final Pointer pErrNo = nativeLib .getFunction ("errno" );
81- return pErrNo .getInt (0 );
70+ assert ret == 0 ;
8271 }
8372
8473 @ Override
0 commit comments