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

C#: Use dedicated lock type where applicable. #18090

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
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 @@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -264,7 +263,7 @@ private void RestoreProjects(IEnumerable<string> projects, out ConcurrentBag<Dep

var isWindows = fileContent.UseWindowsForms || fileContent.UseWpf;

var sync = new object();
var sync = new Lock();
var projectGroups = projects.GroupBy(Path.GetDirectoryName);
Parallel.ForEach(projectGroups, new ParallelOptions { MaxDegreeOfParallelism = DependencyManager.Threads }, projectGroup =>
{
Expand Down Expand Up @@ -346,7 +345,7 @@ private void RestoreProjects(IEnumerable<string> projects, out ConcurrentBag<Dep
compilationInfoContainer.CompilationInfos.Add(("Fallback nuget restore", notYetDownloadedPackages.Count.ToString()));

var successCount = 0;
var sync = new object();
var sync = new Lock();

Parallel.ForEach(notYetDownloadedPackages, new ParallelOptions { MaxDegreeOfParallelism = DependencyManager.Threads }, package =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.IO;
using Semmle.Util;
using Semmle.Util.Logging;
using Semmle.Extraction.CSharp.DependencyFetching;
using System;

namespace Semmle.Extraction.CSharp.Standalone
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using Semmle.Util.Logging;
using Semmle.Extraction.CSharp.DependencyFetching;

namespace Semmle.Extraction.CSharp.Standalone
{
public class Program
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading;
using Semmle.Util.Logging;
using CompilationInfo = (string key, string value);

Expand Down Expand Up @@ -38,7 +39,7 @@ public ExtractionContext(string cwd, string[] args, string outputPath, IEnumerab
// to handle pathological cases.
private const int maxErrors = 1000;

private readonly object mutex = new object();
private readonly Lock mutex = new();

public void Message(Message msg)
{
Expand Down
4 changes: 2 additions & 2 deletions csharp/extractor/Semmle.Util/Logging/PidStreamWriter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.IO;
using System.Diagnostics;
using System.Threading;

namespace Semmle.Util.Logging
{
Expand Down Expand Up @@ -33,6 +33,6 @@ public override void WriteLine(string? format, params object?[] args)
WriteLine(format is null ? format : string.Format(format, args));
}

private readonly object mutex = new object();
private readonly Lock mutex = new();
}
}
2 changes: 1 addition & 1 deletion csharp/extractor/Testrunner/Testrunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/// </summary>
public class Testrunner
{
private static readonly object ConsoleLock = new();
private static readonly Lock ConsoleLock = new();

private static readonly ManualResetEvent Finished = new(false);

Expand Down
Loading