File tree Expand file tree Collapse file tree
main/java/vanilla/java/affinity
test/java/vanilla/java/affinity Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -350,7 +350,24 @@ protected void finalize() throws Throwable {
350350 super .finalize ();
351351 }
352352
353+ /**
354+ * @return unique id for this CPI or -1 if not allocated.
355+ */
353356 public int cpuId () {
354357 return cpuId ;
355358 }
359+
360+ /**
361+ * @return Was a cpu found to bind this lock to.
362+ */
363+ public boolean isAllocated () {
364+ return cpuId >= 0 ;
365+ }
366+
367+ /**
368+ * @return Has this AffinityLock been bound?
369+ */
370+ public boolean isBound () {
371+ return bound ;
372+ }
356373}
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public enum NativeAffinity implements IAffinity {
3636 System .loadLibrary ("affinity" );
3737 loaded = true ;
3838 } catch (UnsatisfiedLinkError ule ) {
39- if (LOGGER .isLoggable (Level .INFO ))
39+ if (LOGGER .isLoggable (Level .INFO ) && System . getProperty ( "os.name" ). equalsIgnoreCase ( "Linux" ) )
4040 LOGGER .info ("Unable to find libaffinity in " + System .getProperty ("java.library.path" ) + " " + ule );
4141 loaded = false ;
4242 }
Original file line number Diff line number Diff line change @@ -135,15 +135,21 @@ public void assignReleaseThread() throws IOException {
135135 public void testIssue21 () {
136136 AffinityLock al = AffinityLock .acquireLock ();
137137 AffinityLock alForAnotherThread = al .acquireLock (AffinityStrategies .ANY );
138- AffinityLock alForAnotherThread2 = al .acquireLock (AffinityStrategies .ANY );
139- assertNotSame (alForAnotherThread , alForAnotherThread2 );
140- assertNotSame (alForAnotherThread .cpuId (), alForAnotherThread2 .cpuId ());
141-
142- al .release ();
138+ if (Runtime .getRuntime ().availableProcessors () > 2 ) {
139+ AffinityLock alForAnotherThread2 = al .acquireLock (AffinityStrategies .ANY );
140+ assertNotSame (alForAnotherThread , alForAnotherThread2 );
141+ assertNotSame (alForAnotherThread .cpuId (), alForAnotherThread2 .cpuId ());
142+
143+ alForAnotherThread2 .release ();
144+ } else {
145+ assertNotSame (alForAnotherThread , al );
146+ assertNotSame (alForAnotherThread .cpuId (), al .cpuId ());
147+ }
143148 alForAnotherThread .release ();
144- alForAnotherThread2 .release ();
149+ al .release ();
145150 }
146151
152+
147153 @ Test
148154 public void testIssue19 () {
149155 AffinityLock al = AffinityLock .acquireLock ();
You can’t perform that action at this time.
0 commit comments