Skip to content

Commit 74d122c

Browse files
AFFINITY-9 Made the bind operation more tolerant of the case when no CPU/Core could be reserved
1 parent d63ec8f commit 74d122c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

affinity/src/main/java/net/openhft/affinity/AffinityLock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void bind(boolean wholeCore) {
212212
throw new IllegalStateException("cpu " + cpuId + " already bound to " + assignedThread);
213213

214214
if (wholeCore) {
215-
lockInventory.bindWhileCore(cpuId);
215+
lockInventory.bindWholeCore(cpuId);
216216
} else if (cpuId >= 0) {
217217
bound = true;
218218
assignedThread = Thread.currentThread();

affinity/src/main/java/net/openhft/affinity/LockInventory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ public final synchronized AffinityLock acquireCore(boolean bind, int cpuId, Affi
9292
return acquireLock(bind, cpuId, strategies);
9393
}
9494

95-
public final synchronized void bindWhileCore(int logicalCoreID) {
95+
public final synchronized void bindWholeCore(int logicalCoreID) {
96+
if (logicalCoreID < 0) {
97+
LOGGER.warning("Can't bind core since it was not possible to reserve it!");
98+
return;
99+
}
100+
96101
int core = toPhysicalCore(logicalCoreID);
97102
for (AffinityLock al : physicalCoreLocks.get(core)) {
98103
if (al.isBound() && al.assignedThread != null && al.assignedThread.isAlive()) {

0 commit comments

Comments
 (0)