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

Remove unnecessary lock in TerminalLogger.UpdateNodeStatus #10045

Merged
merged 2 commits into from May 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/MSBuild/TerminalLogger/TerminalLogger.cs
Expand Up @@ -91,6 +91,10 @@ public ProjectContext(BuildEventContext context)
/// <summary>
/// Tracks the work currently being done by build nodes. Null means the node is not doing any work worth reporting.
/// </summary>
/// <remarks>
/// There is no locking around access to this data structure despite it being accessed concurrently by multiple threads.
/// However, reads and writes to locations in an array is atomic, so locking is not required.
/// </remarks>
private NodeStatus?[] _nodes = Array.Empty<NodeStatus>();

/// <summary>
Expand Down Expand Up @@ -701,11 +705,8 @@ private void TargetStarted(object sender, TargetStartedEventArgs e)

private void UpdateNodeStatus(BuildEventContext buildEventContext, NodeStatus? nodeStatus)
{
lock (_lock)
{
int nodeIndex = NodeIndexForContext(buildEventContext);
_nodes[nodeIndex] = nodeStatus;
}
int nodeIndex = NodeIndexForContext(buildEventContext);
_nodes[nodeIndex] = nodeStatus;
dfederm marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand Down