Skip to content
5 changes: 0 additions & 5 deletions src/Build.UnitTests/BackEnd/BuildManager_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ private void SimpleP2PBuild(BuildParameters buildParameters)
/// A simple successful graph build.
/// </summary>
[Fact]
[ActiveIssue("https://github.com/Microsoft/msbuild/issues/4368")]
public void SimpleGraphBuild()
{
string contents = CleanupFileContents(@"
Expand Down Expand Up @@ -4028,7 +4027,6 @@ handoff logging completion to the BuildManager.
}

[Fact]
[ActiveIssue("https://github.com/Microsoft/msbuild/issues/4368")]
public void GraphBuildValid()
{
string project1 = _env.CreateFile(".proj").Path;
Expand Down Expand Up @@ -4069,7 +4067,6 @@ public void GraphBuildValid()
}

[Fact]
[ActiveIssue("https://github.com/Microsoft/msbuild/issues/4368")]
public void GraphBuildInvalid()
{
string project1 = _env.CreateFile(".proj").Path;
Expand Down Expand Up @@ -4101,7 +4098,6 @@ public void GraphBuildInvalid()
}

[Fact]
[ActiveIssue("https://github.com/Microsoft/msbuild/issues/4368")]
public void GraphBuildFail()
{
string project1 = _env.CreateFile(".proj").Path;
Expand Down Expand Up @@ -4144,7 +4140,6 @@ public void GraphBuildFail()
}

[Fact]
[ActiveIssue("https://github.com/Microsoft/msbuild/issues/4368")]
public void GraphBuildCircular()
{
string project1 = _env.CreateFile(".proj").Path;
Expand Down
1 change: 0 additions & 1 deletion src/Build.UnitTests/Graph/ProjectGraph_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

namespace Microsoft.Build.Experimental.Graph.UnitTests
{
[ActiveIssue("https://github.com/Microsoft/msbuild/issues/4368")]
public class ProjectGraphTests : IDisposable
{
private TestEnvironment _env;
Expand Down
40 changes: 39 additions & 1 deletion src/Build/Collections/CopyOnReadEnumerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections;
using System.Collections.Generic;
using System.Threading;
using Microsoft.Build.Shared;

namespace Microsoft.Build.Collections
Expand All @@ -28,6 +29,8 @@ internal class CopyOnReadEnumerable<T> : IEnumerable<T>
/// </summary>
private readonly object _syncRoot;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can eliminate this field now and use the RW lock? It doesn't matter what the object is so long as it's readonly and private. That will claw back the size increase in this object form adding the RW lock field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregard, I didn't view the full diff. You still use that syncroot in another path.


private readonly ReaderWriterLockSlim _readerWriterLockSlim;

/// <summary>
/// Constructor.
/// </summary>
Expand All @@ -42,6 +45,20 @@ public CopyOnReadEnumerable(IEnumerable<T> backingEnumerable, object syncRoot)
_syncRoot = syncRoot;
}

/// <summary>
/// Constructor.
/// </summary>
/// <param name="backingEnumerable">The collection which serves as a source for enumeration.</param>
/// <param name="readerWriterLock">The object used to synchronize access for copying.</param>
public CopyOnReadEnumerable(IEnumerable<T> backingEnumerable, ReaderWriterLockSlim readerWriterLockSlim)
{
ErrorUtilities.VerifyThrowArgumentNull(backingEnumerable, nameof(backingEnumerable));
ErrorUtilities.VerifyThrowArgumentNull(readerWriterLockSlim, nameof(readerWriterLockSlim));

_backingEnumerable = backingEnumerable;
_readerWriterLockSlim = readerWriterLockSlim;
}

#region IEnumerable<T> Members

/// <summary>
Expand All @@ -62,8 +79,20 @@ public IEnumerator<T> GetEnumerator()

bool isCloneable = false;
bool checkForCloneable = true;
lock (_syncRoot)

object lockObject = _syncRoot;
bool lockWasTaken = false;
try
{
if (lockObject != null)
{
Monitor.Enter(lockObject, ref lockWasTaken);
}
else
{
_readerWriterLockSlim.EnterReadLock();
}

foreach (T item in _backingEnumerable)
{
if (checkForCloneable)
Expand All @@ -80,6 +109,15 @@ public IEnumerator<T> GetEnumerator()
list.Add(copiedItem);
}
}
finally
{
if (lockWasTaken)
{
Monitor.Exit(lockObject);
}

_readerWriterLockSlim?.ExitReadLock();
}

return list.GetEnumerator();
}
Expand Down
Loading