private static Tuple <DupItem, TreeNodeDupMd5Full> AddDup(FileInfo fInfo, Action <DupItem> doLink) { var d = new DupItem(fInfo); var s = d.Size; var n = Root.Get(s); if (n == null) { lock (RootLock) n = Root.GetOrNew(s); } Task.Run(() => doLink(d)); var tFull = n.Add(d); return(Tuple.Create(d, tFull)); }
public TreeNodeDupMd5Full Add(DupItem d) { if (Existing != null) { KeyBeforeLock(d); // do this outside lock } IList <Tuple <TreeNodeBase, DupItem> > l; lock (Lock) { if (Existing == null) { Existing = d; return(null); } l = AddNonFirstLock(d); // do lock critical } return(AddNonFirstPostLock(l)); // do stuff not needing lock at this level }
protected override IList <Tuple <TreeNodeBase, DupItem> > AddNonFirstLock(DupItem d) { var unhandSibs = SubTree.Count == 0 ? new[] { Existing, d } : new[] { d }; return(unhandSibs .Select(s => Tuple.Create((TreeNodeBase)SubTree.GetOrNew(KeyBeforeLock(s)), s)) .ToList()); }
protected override string KeyBeforeLock(DupItem x) { return(x.GetMd5OneBlock()); }
protected abstract IList <Tuple <TreeNodeBase, DupItem> > AddNonFirstLock(DupItem d);
protected virtual string KeyBeforeLock(DupItem x) { return(null); }
protected override IList <Tuple <TreeNodeBase, DupItem> > AddNonFirstLock(DupItem d) { return(null); }