Skip to content

Commit e538d4b

Browse files
committed
Only release affinity if it was narrowed in the first place.
1 parent 6dcc185 commit e538d4b

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
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
@@ -353,7 +353,7 @@ public AffinityLock acquireLock(AffinityStrategy... strategies) {
353353
* Release the current AffinityLock which can be discarded.
354354
*/
355355
public void release() {
356-
if (cpuId == ANY_CPU || !reservable)
356+
if (cpuId == ANY_CPU)
357357
return;
358358
// expensive if not actually used.
359359
lockInventory.release();

affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public void assignReleaseThread() throws IOException {
133133
System.out.println("Cannot run affinity test as this system doesn't have a /proc/cpuinfo file");
134134
return;
135135
}
136+
136137
AffinityLock.cpuLayout(VanillaCpuLayout.fromCpuInfo());
137138

138139
assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity());
@@ -229,6 +230,7 @@ public void shouldReturnLockForSpecifiedCpu() {
229230
try (final AffinityLock affinityLock = AffinityLock.acquireLock(3)) {
230231
assertThat(affinityLock.cpuId(), is(3));
231232
}
233+
assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity());
232234
}
233235

234236
@Test

0 commit comments

Comments
 (0)