From 199bfd11dadbbe560d7dc54143ea55ac4ce35e0e Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Mon, 25 Nov 2024 13:19:59 +0100 Subject: [PATCH] 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);