Fix same-key check in linkToSegmentContextsChain()

This commit is contained in:
leventov
2015-09-29 00:42:20 +03:00
parent b9084b1918
commit 0a5bc1e50c
3 changed files with 22 additions and 8 deletions
@@ -318,13 +318,8 @@ public abstract class SegmentStages implements SegmentLock, LocksInterface {
private void linkToSegmentContextsChain() {
LocksInterface innermostContextOnThisSegment = rootContextOnThisSegment;
while (true) {
if (innermostContextOnThisSegment instanceof KeySearch) {
Data key = ((KeySearch) innermostContextOnThisSegment).inputKey;
if (Objects.equals(key, ((KeySearch) (Object) this).inputKey)) {
throw new IllegalStateException("Nested same-thread contexts cannot access " +
"the same key " + key);
}
}
checkNestedContextsQueryDifferentKeys(innermostContextOnThisSegment);
if (innermostContextOnThisSegment.nextNode() == null)
break;
innermostContextOnThisSegment = innermostContextOnThisSegment.nextNode();
@@ -332,6 +327,18 @@ public abstract class SegmentStages implements SegmentLock, LocksInterface {
innermostContextOnThisSegment.setNextNode(this);
}
public void checkNestedContextsQueryDifferentKeys(
LocksInterface innermostContextOnThisSegment) {
// TODO Spoon doesn't replace RHS instanceof occurances
if (innermostContextOnThisSegment.getClass() == this.getClass()) {
Data key = ((KeySearch) innermostContextOnThisSegment).inputKey;
if (Objects.equals(key, ((KeySearch) (Object) this).inputKey)) {
throw new IllegalStateException("Nested same-thread contexts cannot access " +
"the same key " + key);
}
}
}
@Stage("Locks")
private void unlinkFromSegmentContextsChain() {
LocksInterface prevContext = rootContextOnThisSegment;
@@ -17,6 +17,7 @@
package net.openhft.chronicle.hash.impl.stage.iter;
import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder;
import net.openhft.chronicle.hash.impl.stage.entry.LocksInterface;
import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages;
import net.openhft.chronicle.hash.impl.stage.entry.HashLookupSearch;
import net.openhft.chronicle.hash.impl.stage.query.KeySearch;
@@ -48,4 +49,10 @@ public abstract class IterationSegmentStages extends SegmentStages {
segmentTier = tier;
segmentBaseAddr = tierBaseAddr;
}
@Override
public void checkNestedContextsQueryDifferentKeys(
LocksInterface innermostContextOnThisSegment) {
// this check is relevant only for query contexts
}
}