From ddba49dbea92aa7c9322efa8d3112f79ab24bac7 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Sun, 7 May 2017 16:28:49 -0700 Subject: [PATCH] tst: memfs-dotnet: remove unnecessary OpenNodeSet --- tst/memfs-dotnet/Program.cs | 41 +++++++++---------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/tst/memfs-dotnet/Program.cs b/tst/memfs-dotnet/Program.cs index ed24bd4f..dd3b476d 100644 --- a/tst/memfs-dotnet/Program.cs +++ b/tst/memfs-dotnet/Program.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Security.AccessControl; +using System.Threading; using Fsp; using VolumeInfo = Fsp.Interop.VolumeInfo; @@ -191,7 +192,6 @@ namespace memfs Boolean CaseInsensitive, UInt32 MaxFileNodes, UInt32 MaxFileSize, String RootSddl) { this.FileNodeMap = new FileNodeMap(CaseInsensitive); - this.OpenNodeSet = new HashSet(); this.MaxFileNodes = MaxFileNodes; this.MaxFileSize = MaxFileSize; @@ -326,7 +326,7 @@ namespace memfs } FileNodeMap.Insert(FileNode); - InsertOpenNode(FileNode); + Interlocked.Increment(ref FileNode.OpenCount); FileNode0 = FileNode; FileInfo = FileNode.GetFileInfo(); NormalizedName = FileNode.FileName; @@ -359,7 +359,7 @@ namespace memfs return Result; } - InsertOpenNode(FileNode); + Interlocked.Increment(ref FileNode.OpenCount); FileNode0 = FileNode; FileInfo = FileNode.GetFileInfo(); NormalizedName = FileNode.FileName; @@ -381,16 +381,13 @@ namespace memfs Int32 Result; List StreamFileNames = new List(FileNodeMap.GetStreamFileNames(FileNode)); - lock (OpenNodeSet) + foreach (String StreamFileName in StreamFileNames) { - foreach (String StreamFileName in StreamFileNames) - { - FileNode StreamNode = FileNodeMap.Get(StreamFileName); - if (null == StreamNode) - continue; /* should not happen */ - if (!OpenNodeSet.Contains(StreamNode)) - FileNodeMap.Remove(StreamNode); - } + FileNode StreamNode = FileNodeMap.Get(StreamFileName); + if (null == StreamNode) + continue; /* should not happen */ + if (0 == FileNode.OpenCount) + FileNodeMap.Remove(StreamNode); } Result = SetFileSizeInternal(FileNode, AllocationSize, true); @@ -465,7 +462,7 @@ namespace memfs Object FileDesc) { FileNode FileNode = (FileNode)FileNode0; - RemoveOpenNode(FileNode); + Interlocked.Decrement(ref FileNode.OpenCount); } public override Int32 Read( @@ -960,25 +957,7 @@ namespace memfs return false; } - private void InsertOpenNode(FileNode FileNode) - { - lock (OpenNodeSet) - { - if (1 == ++FileNode.OpenCount) - OpenNodeSet.Add(FileNode); - } - } - private void RemoveOpenNode(FileNode FileNode) - { - lock (OpenNodeSet) - { - if (0 == --FileNode.OpenCount) - OpenNodeSet.Remove(FileNode); - } - } - private FileNodeMap FileNodeMap; - private HashSet OpenNodeSet; private UInt32 MaxFileNodes; private UInt32 MaxFileSize; private String VolumeLabel;