Skip to content

Commit eae579b

Browse files
committed
Delay producing a warning until a lock is actually used
1 parent 125ec45 commit eae579b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ private static BitSet getReservedAffinity0() {
121121
reserverable.set(1, PROCESSORS, true);
122122
reserverable.andNot(BASE_AFFINITY);
123123
if (reserverable.isEmpty() && PROCESSORS > 1) {
124-
LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1));
125124
// make all but first CPUs available
126125
reserverable.set(1, PROCESSORS);
127126
return reserverable;
@@ -149,6 +148,14 @@ public static AffinityLock acquireLock() {
149148
return acquireLock(true);
150149
}
151150

151+
static class Warnings {
152+
static void warmNoReservedCPUs() {
153+
if (RESERVED_AFFINITY.isEmpty() && PROCESSORS > 1) {
154+
LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1));
155+
}
156+
}
157+
}
158+
152159
/**
153160
* Assign any free core to this thread. <p> In reality, only one cpu is assigned, the rest of
154161
* the threads for that core are reservable so they are not used.
@@ -294,6 +301,7 @@ public static AffinityLock acquireCore(boolean bind) {
294301
}
295302

296303
private static AffinityLock acquireLock(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) {
304+
Warnings.warmNoReservedCPUs();
297305
return LOCK_INVENTORY.acquireLock(bind, cpuId, strategies);
298306
}
299307

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

312320
private static AffinityLock acquireCore(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) {
321+
Warnings.warmNoReservedCPUs();
313322
return LOCK_INVENTORY.acquireCore(bind, cpuId, strategies);
314323
}
315324

0 commit comments

Comments
 (0)