コード例 #1
0
 public static void sched_setaffinity(final BitSet affinity) {
   final CLibrary lib = CLibrary.INSTANCE;
   final cpu_set_t cpuset = new cpu_set_t();
   final int size =
       version.isSameOrNewer(VERSION_2_6) ? cpu_set_t.SIZE_OF_CPU_SET_T : NativeLong.SIZE;
   final long[] bits = affinity.toLongArray();
   for (int i = 0; i < bits.length; i++) {
     if (Platform.is64Bit()) {
       cpuset.__bits[i].setValue(bits[i]);
     } else {
       cpuset.__bits[i * 2].setValue(bits[i] & 0xFFFFFFFFL);
       cpuset.__bits[i * 2 + 1].setValue((bits[i] >>> 32) & 0xFFFFFFFFL);
     }
   }
   try {
     if (lib.sched_setaffinity(0, size, cpuset) != 0) {
       throw new IllegalStateException(
           "sched_setaffinity(0, "
               + size
               + ", 0x"
               + Utilities.toHexString(affinity)
               + ") failed; errno="
               + Native.getLastError());
     }
   } catch (LastErrorException e) {
     throw new IllegalStateException(
         "sched_setaffinity(0, "
             + size
             + ", 0x"
             + Utilities.toHexString(affinity)
             + ") failed; errno="
             + e.getErrorCode(),
         e);
   }
 }
コード例 #2
0
 static {
   if (Platform.isWindows()) {
     String path = System.getProperty("java.library.path");
     String winPath = "c:\\Windows\\" + (Platform.is64Bit() ? "SysWOW64" : "System32");
     if (path == null) path = winPath;
     else path = path + ";" + winPath;
     System.setProperty("java.library.path", path);
   }
 }
コード例 #3
0
ファイル: JPicosat.java プロジェクト: patrick-st/warthog
  public JPicosat(String libDir) throws Exception {
    if (libDir == null || "".equals(libDir)) libDir = "lib";
    StringBuilder pref = new StringBuilder(libDir + DIR);

    if (Platform.isMac())
      if (Platform.is64Bit()) pref.append("/macosx/64");
      else pref.append("/macosx/32");
    else if (Platform.isLinux())
      if (Platform.is64Bit()) pref.append("/linux/64");
      else pref.append("/linux/32");
    else if (Platform.isWindows())
      if (Platform.is64Bit()) pref.append("/win/64");
      else pref.append("/win/32");
    else throw new Exception("JPicosat: Platform unsupported!");

    System.setProperty("jna.library.path", pref.toString());
    INSTANCE = (CPicosat) Native.loadLibrary("picosat", CPicosat.class);
    checkLibraryVersion(pref.toString());
  }
コード例 #4
0
  public static String getCurrentOSAndArchString() {
    String os = System.getProperty("os.name"), arch = System.getProperty("os.arch");

    if (os.equals("Mac OS X")) {
      os = "darwin";
      arch = "fat";
      // arch = Platform.is64Bit() ? "64" : "32";
    } else if (os.startsWith("Windows")) {
      return "win" + (Platform.is64Bit() ? "64" : "32");
    } else if (os.matches("SunOS|Solaris")) os = "solaris";

    return os + "-" + arch;
  }
コード例 #5
0
  public static int sched_getcpu() {
    final CLibrary lib = CLibrary.INSTANCE;
    try {
      final int ret = lib.sched_getcpu();
      if (ret < 0) {
        throw new IllegalStateException("sched_getcpu() failed; errno=" + Native.getLastError());
      }
      return ret;
    } catch (LastErrorException e) {
      throw new IllegalStateException("sched_getcpu() failed; errno=" + e.getErrorCode(), e);
    } catch (UnsatisfiedLinkError ule) {
      try {
        final IntByReference cpu = new IntByReference();
        final IntByReference node = new IntByReference();
        final int ret = lib.syscall(318, cpu, node, null);
        if (ret != 0) {
          throw new IllegalStateException("getcpu() failed; errno=" + Native.getLastError());
        }
        return cpu.getValue();
      } catch (LastErrorException lee) {
        if (lee.getErrorCode() == 38 && Platform.is64Bit()) { // unknown call
          final Pointer getcpuAddr = new Pointer((-10L << 20) + 1024L * 2L);
          final Function getcpu = Function.getFunction(getcpuAddr, Function.C_CONVENTION);
          final IntByReference cpu = new IntByReference();
          if (getcpu.invokeInt(new Object[] {cpu, null, null}) < 0) {
            throw new IllegalStateException("getcpu() failed; errno=" + Native.getLastError());

          } else {
            return cpu.getValue();
          }
        } else {
          throw new IllegalStateException("getcpu() failed; errno=" + lee.getErrorCode(), lee);
        }
      }
    }
  }