Skip to content

Commit

Permalink
Delay producing a warning until a lock is actually used
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-lawrey committed Sep 5, 2022
1 parent 125ec45 commit eae579b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion affinity/src/main/java/net/openhft/affinity/AffinityLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ private static BitSet getReservedAffinity0() {
reserverable.set(1, PROCESSORS, true);
reserverable.andNot(BASE_AFFINITY);
if (reserverable.isEmpty() && PROCESSORS > 1) {
LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1));
// make all but first CPUs available
reserverable.set(1, PROCESSORS);
return reserverable;
Expand Down Expand Up @@ -149,6 +148,14 @@ public static AffinityLock acquireLock() {
return acquireLock(true);
}

static class Warnings {
static void warmNoReservedCPUs() {
if (RESERVED_AFFINITY.isEmpty() && PROCESSORS > 1) {
LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1));
}
}
}

/**
* Assign any free core to this thread. <p> In reality, only one cpu is assigned, the rest of
* the threads for that core are reservable so they are not used.
Expand Down Expand Up @@ -294,6 +301,7 @@ public static AffinityLock acquireCore(boolean bind) {
}

private static AffinityLock acquireLock(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) {
Warnings.warmNoReservedCPUs();
return LOCK_INVENTORY.acquireLock(bind, cpuId, strategies);
}

Expand All @@ -310,6 +318,7 @@ private static AffinityLock tryAcquireLock(boolean bind, int cpuId) {
}

private static AffinityLock acquireCore(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) {
Warnings.warmNoReservedCPUs();
return LOCK_INVENTORY.acquireCore(bind, cpuId, strategies);
}

Expand Down

0 comments on commit eae579b

Please sign in to comment.