From 38c1e1c7238b9da90397aba984fdebb315eb0055 Mon Sep 17 00:00:00 2001 From: leventov Date: Sat, 1 Aug 2015 23:54:55 +0300 Subject: [PATCH] Make contexts follow the spec -- nested contexts on the same key should be forbidden --- .../hash/impl/stage/entry/SegmentStages.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/SegmentStages.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/SegmentStages.java index 0fa5fd413..174a6f825 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/SegmentStages.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/SegmentStages.java @@ -16,24 +16,23 @@ package net.openhft.chronicle.hash.impl.stage.entry; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.SegmentLock; -import net.openhft.chronicle.hash.impl.BigSegmentHeader; -import net.openhft.chronicle.hash.impl.LocalLockState; -import net.openhft.chronicle.hash.impl.SegmentHeader; -import net.openhft.chronicle.hash.impl.VanillaChronicleHash; +import net.openhft.chronicle.hash.impl.*; import net.openhft.chronicle.hash.impl.stage.hash.Chaining; import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation; -import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder; +import net.openhft.chronicle.hash.impl.stage.query.HashQuery; import net.openhft.chronicle.hash.locks.InterProcessLock; -import net.openhft.chronicle.hash.locks.InterProcessReadWriteUpdateLock; import net.openhft.lang.collection.DirectBitSet; import net.openhft.lang.collection.SingleThreadedDirectBitSet; import net.openhft.lang.io.MultiStoreBytes; import net.openhft.sg.Stage; -import net.openhft.sg.Staged; import net.openhft.sg.StageRef; +import net.openhft.sg.Staged; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + import static net.openhft.chronicle.hash.impl.LocalLockState.UNLOCKED; @Staged @@ -269,8 +268,16 @@ public abstract class SegmentStages implements SegmentLock { @Stage("Locks") private void linkToSegmentContextsChain() { SegmentStages innermostContextOnThisSegment = rootContextOnThisSegment; - while (innermostContextOnThisSegment.nextNode != null) + while (true) { + Data key = ((HashQuery) (Object) innermostContextOnThisSegment).inputKey; + if (Objects.equals(key, ((HashQuery) (Object) this).inputKey)) { + throw new IllegalStateException("Nested same-thread contexts cannot access " + + "the same key " + key); + } + if (innermostContextOnThisSegment.nextNode == null) + break; innermostContextOnThisSegment = innermostContextOnThisSegment.nextNode; + } innermostContextOnThisSegment.nextNode = this; }