From dde0281d25a7653359a593915620ef188940387f Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Mon, 25 Nov 2024 13:19:59 +0100 Subject: [PATCH 1/2] C#: Use dedicated lock type where applicable. --- .../NugetPackageRestorer.cs | 5 ++--- .../Semmle.Extraction.CSharp/Extractor/ExtractionContext.cs | 3 ++- csharp/extractor/Semmle.Util/Logging/PidStreamWriter.cs | 4 ++-- csharp/extractor/Testrunner/Testrunner.cs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs index 3895db3e4d40..f30760981f3a 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs @@ -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; @@ -264,7 +263,7 @@ private void RestoreProjects(IEnumerable projects, out ConcurrentBag { @@ -346,7 +345,7 @@ private void RestoreProjects(IEnumerable projects, out ConcurrentBag { diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/ExtractionContext.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/ExtractionContext.cs index 619eb9953471..262475ca5a16 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/ExtractionContext.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/ExtractionContext.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading; using Semmle.Util.Logging; using CompilationInfo = (string key, string value); @@ -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) { diff --git a/csharp/extractor/Semmle.Util/Logging/PidStreamWriter.cs b/csharp/extractor/Semmle.Util/Logging/PidStreamWriter.cs index 7d9599298d65..cf4d8be52e52 100644 --- a/csharp/extractor/Semmle.Util/Logging/PidStreamWriter.cs +++ b/csharp/extractor/Semmle.Util/Logging/PidStreamWriter.cs @@ -1,5 +1,5 @@ using System.IO; -using System.Diagnostics; +using System.Threading; namespace Semmle.Util.Logging { @@ -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(); } } diff --git a/csharp/extractor/Testrunner/Testrunner.cs b/csharp/extractor/Testrunner/Testrunner.cs index 6280a8c1be2a..d772ca903f7a 100644 --- a/csharp/extractor/Testrunner/Testrunner.cs +++ b/csharp/extractor/Testrunner/Testrunner.cs @@ -14,7 +14,7 @@ /// public class Testrunner { - private static readonly object ConsoleLock = new(); + private static readonly Lock ConsoleLock = new(); private static readonly ManualResetEvent Finished = new(false); From 38e3913fa90618fe6d7f9cebf39ab2209066772a Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Wed, 27 Nov 2024 10:03:17 +0100 Subject: [PATCH 2/2] C#: Remove redundant using statements. --- .../extractor/Semmle.Extraction.CSharp.Standalone/Options.cs | 4 +--- .../extractor/Semmle.Extraction.CSharp.Standalone/Program.cs | 5 ----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp.Standalone/Options.cs b/csharp/extractor/Semmle.Extraction.CSharp.Standalone/Options.cs index 39c363a77531..64d7535ee2a1 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.Standalone/Options.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.Standalone/Options.cs @@ -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 { diff --git a/csharp/extractor/Semmle.Extraction.CSharp.Standalone/Program.cs b/csharp/extractor/Semmle.Extraction.CSharp.Standalone/Program.cs index fc13b774f4f1..475847be5765 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.Standalone/Program.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.Standalone/Program.cs @@ -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