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);
   }
 }
Example #2
0
  public static void main(String[] args) {
    BitSet bits1 = new BitSet();
    BitSet bits2 = new BitSet(16);

    bits1.set(1);
    bits1.set(2);
    bits1.set(3);
    bits2.set(2);
    bits2.set(3);
    bits2.set(5);
    bits2.set(4);

    System.out.println(bits1);
    System.out.println(bits2);
    // bits2.andNot(bits1);
    for (int i = 0; i < bits1.toByteArray().length; i++) {
      System.out.println(bits1.toByteArray().length);
    }
    // System.out.println();

    long l[] = bits1.toLongArray();
    System.out.println(l.length);
  }
 /** {@inheritDoc} */
 @Override
 public void writeBitSet(BitSet val) {
   writeLongArray(val != null ? val.toLongArray() : null);
 }