private static AffinityLock acquireCore(boolean bind, int cpuId, AffinityStrategy... strategies) { synchronized (AffinityLock.class) { for (AffinityStrategy strategy : strategies) { LOOP: for (AffinityLock[] als : CORES.descendingMap().values()) { for (AffinityLock al : als) if (!al.canReserve() || !strategy.matches(cpuId, al.cpuId)) continue LOOP; final AffinityLock al = als[0]; al.assignCurrentThread(bind, true); return al; } } } if (LOGGER.isLoggable(Level.WARNING)) LOGGER.warning("No reservable Core for " + Thread.currentThread()); return acquireLock(bind, cpuId, strategies); }
private static AffinityLock acquireLock(boolean bind, int cpuId, AffinityStrategy... strategies) { synchronized (AffinityLock.class) { for (AffinityStrategy strategy : strategies) { // consider all processors except cpu 0 which is usually used by the OS. // if you have only one core, this library is not appropriate in any case. for (int i = LOCKS.length - 1; i > 0; i--) { AffinityLock al = LOCKS[i]; if (al.canReserve() && (cpuId < 0 || strategy.matches(cpuId, al.cpuId))) { al.assignCurrentThread(bind, false); return al; } } } } if (LOGGER.isLoggable(Level.WARNING)) LOGGER.warning("No reservable CPU for " + Thread.currentThread()); return AffinityLock.NONE; }