77import java .util .logging .Level ;
88import 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