Skip to content

Commit 4e8bf9c

Browse files
AFFINITY-6 Minor changes to further facilitate reuse
1 parent 729907e commit 4e8bf9c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
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
@@ -44,7 +44,7 @@ public class AffinityLock {
4444
public static final long BASE_AFFINITY = AffinitySupport.getAffinity();
4545
public static final long RESERVED_AFFINITY = getReservedAffinity0();
4646

47-
static final LockInventory LOCK_INVENTORY = new LockInventory(new NoCpuLayout(PROCESSORS));
47+
private static final LockInventory LOCK_INVENTORY = new LockInventory(new NoCpuLayout(PROCESSORS));
4848

4949
static {
5050
try {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.logging.Level;
88
import java.util.logging.Logger;
99

10-
class LockInventory { //todo: review and simplify code
10+
class LockInventory {
1111

1212
private static final Logger LOGGER = Logger.getLogger(LockInventory.class.getName());
1313

@@ -43,7 +43,7 @@ public final synchronized void set(CpuLayout cpuLayout) {
4343
if (LOGGER.isLoggable(Level.FINE)) {
4444
LOGGER.fine("cpu " + i + " base= " + base + " reservable= " + reservable);
4545
}
46-
AffinityLock lock = logicalCoreLocks[i] = new AffinityLock(i, base, reservable, this);
46+
AffinityLock lock = logicalCoreLocks[i] = newLock(i, base, reservable);
4747

4848
int layoutId = lock.cpuId();
4949
int physicalCore = toPhysicalCore(layoutId);
@@ -70,7 +70,7 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi
7070
if (LOGGER.isLoggable(Level.WARNING)) {
7171
LOGGER.warning("No reservable CPU for " + Thread.currentThread());
7272
}
73-
return new AffinityLock(-1, false, false, this);
73+
return newLock(-1, false, false);
7474
}
7575

7676
public final synchronized AffinityLock acquireCore(boolean bind, int cpuId, AffinityStrategy... strategies) {
@@ -137,6 +137,10 @@ public final synchronized String dumpLocks() {
137137
return dumpLocks(logicalCoreLocks);
138138
}
139139

140+
protected AffinityLock newLock(int cpuId, boolean base, boolean reservable) {
141+
return new AffinityLock(cpuId, base, reservable, this);
142+
}
143+
140144
private void reset(CpuLayout cpuLayout) {
141145
this.cpuLayout = cpuLayout;
142146
this.logicalCoreLocks = new AffinityLock[cpuLayout.cpus()];

0 commit comments

Comments
 (0)