Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RecentCache node handle comparison bugfix #13

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void DeleteAll()
public abstract ILockStrategy CreateLock(NodeHandle handle, out object refobj);
protected abstract NodePin Lock(NodePin parent, LockType ltype, NodeHandle child);

public NodePin LockRoot(LockType ltype)
public virtual NodePin LockRoot(LockType ltype)
{
return Lock(null, ltype, RootHandle);
}
Expand Down
21 changes: 17 additions & 4 deletions src/CSharpTest.Net.Collections/Collections/NodeCache.Normal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public override ILockStrategy CreateLock(NodeHandle handle, out object refobj)
}

protected override NodePin Lock(NodePin parent, LockType ltype, NodeHandle child)
{
return LockInternal(parent, ltype, child, false);
}

private NodePin LockInternal(NodePin parent, LockType ltype, NodeHandle child, bool ignoreHandleComparison)
{
CacheEntry entry = GetCache(child, false);

Expand All @@ -200,10 +205,13 @@ protected override NodePin Lock(NodePin parent, LockType ltype, NodeHandle child
if (node == null)
{
InvalidNodeHandleException.Assert(
Storage.TryGetNode(child.StoreHandle, out node, NodeSerializer)
&& node != null
&& node.StorageHandle.Equals(entry.Handle.StoreHandle)
);
Storage.TryGetNode(child.StoreHandle, out node, NodeSerializer) && node != null &&
ignoreHandleComparison
? true
: node.StorageHandle.Equals(entry.Handle.StoreHandle));



Node old = Interlocked.CompareExchange(ref entry.Node, node, null);
Assert(null == old, "Collision on cache load.");
}
Expand Down Expand Up @@ -246,6 +254,11 @@ public override void UpdateNode(NodePin node)
Assert(ReferenceEquals(old, node.Original), "Node was modified without lock");
}
}

public override NodePin LockRoot(LockType ltype)
{
return LockInternal(null, ltype, RootHandle, true);
}
}
}
}