Merge pull request #18090 from michaelnebel/csharp/locks

C#: Use dedicated lock type where applicable.
This commit is contained in:
Michael Nebel
2024-12-05 10:52:34 +01:00
committed by GitHub
6 changed files with 8 additions and 15 deletions

View File

@@ -4,7 +4,6 @@ using System.Collections.Generic;
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 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
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 =>
{
@@ -346,7 +345,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
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 =>
{

View File

@@ -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
{

View File

@@ -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

View File

@@ -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 @@ namespace Semmle.Extraction.CSharp
// 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)
{

View File

@@ -1,5 +1,5 @@
using System.IO;
using System.Diagnostics;
using System.Threading;
namespace Semmle.Util.Logging
{
@@ -33,6 +33,6 @@ namespace Semmle.Util.Logging
WriteLine(format is null ? format : string.Format(format, args));
}
private readonly object mutex = new object();
private readonly Lock mutex = new();
}
}

View File

@@ -14,7 +14,7 @@ using System;
/// </summary>
public class Testrunner
{
private static readonly object ConsoleLock = new();
private static readonly Lock ConsoleLock = new();
private static readonly ManualResetEvent Finished = new(false);