Skip to content

Commit 8b22685

Browse files
committed
Improve testing for windows.
1 parent 62ee4a9 commit 8b22685

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

src/main/java/vanilla/java/affinity/AffinityLock.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

src/main/java/vanilla/java/affinity/impl/NativeAffinity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

src/test/java/vanilla/java/affinity/AffinityLockTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)