File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed
main/java/net/openhft/affinity
test/java/net/openhft/affinity/impl Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change 2121import org .jetbrains .annotations .Nullable ;
2222
2323import java .util .concurrent .ThreadFactory ;
24+ import java .util .concurrent .atomic .AtomicReference ;
2425
2526/**
2627 * This is a ThreadFactory which assigns threads based the strategies provided.
@@ -56,17 +57,19 @@ public synchronized Thread newThread(@NotNull final Runnable r) {
5657 Thread t = new Thread (new Runnable () {
5758 @ Override
5859 public void run () {
59- AffinityLock al = lastAffinityLock == null ? AffinityLock .acquireLock () : lastAffinityLock .acquireLock (strategies );
60- try {
61- if (al .cpuId () >= 0 )
62- lastAffinityLock = al ;
60+ try (AffinityLock ignored = acquireLockBasedOnLast ()) {
6361 r .run ();
64- } finally {
65- al .release ();
6662 }
6763 }
6864 }, name2 );
6965 t .setDaemon (daemon );
7066 return t ;
7167 }
68+
69+ private synchronized AffinityLock acquireLockBasedOnLast () {
70+ AffinityLock al = lastAffinityLock == null ? AffinityLock .acquireLock () : lastAffinityLock .acquireLock (strategies );
71+ if (al .cpuId () >= 0 )
72+ lastAffinityLock = al ;
73+ return al ;
74+ }
7275}
Original file line number Diff line number Diff line change @@ -70,11 +70,9 @@ public void setAffinityCompletesGracefully() {
7070 }
7171
7272 @ Test
73- @ Ignore ("TODO FIX" )
7473 public void getAffinityReturnsValuePreviouslySet () {
7574 final IAffinity impl = getImpl ();
76- final int cores = CORES ;
77- for (int core = 0 ; core < cores ; core ++) {
75+ for (int core = 0 ; core < CORES ; core ++) {
7876 final BitSet mask = new BitSet ();
7977 mask .set (core , true );
8078 getAffinityReturnsValuePreviouslySet (impl , mask );
You can’t perform that action at this time.
0 commit comments