Skip to content

Commit 7f2e43e

Browse files
committed
fix NPE
1 parent 9d92e04 commit 7f2e43e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.IOException;
2626
import java.nio.channels.ClosedByInterruptException;
27+
import java.util.Map;
2728
import java.util.NavigableMap;
2829
import java.util.TreeMap;
2930

@@ -117,6 +118,24 @@ public final synchronized void set(CpuLayout cpuLayout) {
117118
}
118119
locks[cpuLayout.threadId(layoutId)] = lock;
119120
}
121+
shrink(physicalCoreLocks);
122+
}
123+
124+
/**
125+
* If some CPUs are hyper-threaded, but not others, fix up the HT CPUs
126+
*/
127+
private void shrink(NavigableMap<Integer, AffinityLock[]> physicalCoreLocks) {
128+
for (Map.Entry<Integer, AffinityLock[]> e : physicalCoreLocks.entrySet()) {
129+
final AffinityLock[] locks = e.getValue();
130+
for (int i=0; i<locks.length; i++) {
131+
if (locks[i] == null) {
132+
final AffinityLock[] locks2 = new AffinityLock[i];
133+
System.arraycopy(locks, 0, locks2, 0, i);
134+
physicalCoreLocks.put(e.getKey(), locks2);
135+
break;
136+
}
137+
}
138+
}
120139
}
121140

122141
public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, AffinityStrategy... strategies) {

0 commit comments

Comments
 (0)