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 thread-safeness from ApplyChangesToWorkspaceContext #4187

Merged
Merged
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 @@ -16,6 +16,11 @@ namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices
/// <summary>
/// Applies <see cref="IProjectVersionedValue{T}"/> values to a <see cref="IWorkspaceProjectContext"/>.
/// </summary>
/// <remarks>
/// This class is not thread-safe and it is up to callers to prevent overlapping of calls to
/// <see cref="ApplyProjectBuild(IProjectVersionedValue{IProjectSubscriptionUpdate}, bool, CancellationToken)"/> and
/// <see cref="ApplyProjectEvaluation(IProjectVersionedValue{IProjectSubscriptionUpdate}, bool, CancellationToken)"/>.
/// </remarks>
[Export(typeof(IApplyChangesToWorkspaceContext))]
internal class ApplyChangesToWorkspaceContext : OnceInitializedOnceDisposed, IApplyChangesToWorkspaceContext
{
Expand Down Expand Up @@ -46,74 +51,59 @@ public void Initialize(IWorkspaceProjectContext context)
{
Requires.NotNull(context, nameof(context));

lock (SyncObject)
{
if (_context != null)
throw new InvalidOperationException("Already initialized.");
if (_context != null)
throw new InvalidOperationException("Already initialized.");

_context = context;
_context = context;

EnsureInitialized();
}
EnsureInitialized();
}

public void ApplyProjectBuild(IProjectVersionedValue<IProjectSubscriptionUpdate> update, bool isActiveContext, CancellationToken cancellationToken)
{
Requires.NotNull(update, nameof(update));

lock (SyncObject)
{
VerifyInitializedAndNotDisposed();

IProjectChangeDescription projectChange = update.Value.ProjectChanges[ProjectBuildRuleName];
VerifyInitializedAndNotDisposed();

if (projectChange.Difference.AnyChanges)
{
IComparable version = GetConfiguredProjectVersion(update);
IProjectChangeDescription projectChange = update.Value.ProjectChanges[ProjectBuildRuleName];

ProcessOptions(projectChange.After);
ProcessCommandLine(version, projectChange.Difference, isActiveContext, cancellationToken);
ProcessProjectBuildFailure(projectChange.After);
}
if (projectChange.Difference.AnyChanges)
{
IComparable version = GetConfiguredProjectVersion(update);

ProcessOptions(projectChange.After);
ProcessCommandLine(version, projectChange.Difference, isActiveContext, cancellationToken);
ProcessProjectBuildFailure(projectChange.After);
}
}

public void ApplyProjectEvaluation(IProjectVersionedValue<IProjectSubscriptionUpdate> update, bool isActiveContext, CancellationToken cancellationToken)
{
Requires.NotNull(update, nameof(update));

lock (SyncObject)
{
VerifyInitializedAndNotDisposed();
VerifyInitializedAndNotDisposed();

IComparable version = GetConfiguredProjectVersion(update);
IComparable version = GetConfiguredProjectVersion(update);

ProcessProjectEvaluationHandlers(version, update, isActiveContext, cancellationToken);
}
ProcessProjectEvaluationHandlers(version, update, isActiveContext, cancellationToken);
}

public IEnumerable<string> GetProjectEvaluationRules()
{
lock (SyncObject)
{
VerifyInitializedAndNotDisposed();
VerifyInitializedAndNotDisposed();

return _handlers.Select(e => e.Value)
.OfType<IProjectEvaluationHandler>()
.Select(e => e.ProjectEvaluationRule)
.Distinct(StringComparers.RuleNames)
.ToArray();
}
return _handlers.Select(e => e.Value)
.OfType<IProjectEvaluationHandler>()
.Select(e => e.ProjectEvaluationRule)
.Distinct(StringComparers.RuleNames)
.ToArray();
}

public IEnumerable<string> GetProjectBuildRules()
{
lock (SyncObject)
{
VerifyInitializedAndNotDisposed();
VerifyInitializedAndNotDisposed();

return new string[] { ProjectBuildRuleName };
}
return new string[] { ProjectBuildRuleName };
}

protected override void Dispose(bool disposing)
Expand Down Expand Up @@ -198,7 +188,7 @@ private void ProcessProjectEvaluationHandlers(IComparable version, IProjectVersi
IProjectChangeDescription projectChange = update.Value.ProjectChanges[evaluationHandler.ProjectEvaluationRule];
if (!projectChange.Difference.AnyChanges)
continue;

evaluationHandler.Handle(version, projectChange, isActiveContext, _logger);
}
}
Expand Down