Skip to content
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);
}
}
}
}