Skip to content

Commit 80be95d

Browse files
authored
Merge pull request #18090 from michaelnebel/csharp/locks
C#: Use dedicated lock type where applicable.
2 parents 65a4dc3 + 38e3913 commit 80be95d

File tree

6 files changed

+8
-15
lines changed

6 files changed

+8
-15
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.IO;
55
using System.Linq;
66
using System.Net.Http;
7-
using System.Security.Cryptography;
87
using System.Text;
98
using System.Text.RegularExpressions;
109
using System.Threading;
@@ -264,7 +263,7 @@ private void RestoreProjects(IEnumerable<string> projects, out ConcurrentBag<Dep
264263

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

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

348347
var successCount = 0;
349-
var sync = new object();
348+
var sync = new Lock();
350349

351350
Parallel.ForEach(notYetDownloadedPackages, new ParallelOptions { MaxDegreeOfParallelism = DependencyManager.Threads }, package =>
352351
{

csharp/extractor/Semmle.Extraction.CSharp.Standalone/Options.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
using System;
12
using System.IO;
23
using Semmle.Util;
3-
using Semmle.Util.Logging;
4-
using Semmle.Extraction.CSharp.DependencyFetching;
5-
using System;
64

75
namespace Semmle.Extraction.CSharp.Standalone
86
{

csharp/extractor/Semmle.Extraction.CSharp.Standalone/Program.cs

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using Semmle.Util.Logging;
4-
using Semmle.Extraction.CSharp.DependencyFetching;
5-
61
namespace Semmle.Extraction.CSharp.Standalone
72
{
83
public class Program

csharp/extractor/Semmle.Extraction.CSharp/Extractor/ExtractionContext.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Threading;
23
using Semmle.Util.Logging;
34
using CompilationInfo = (string key, string value);
45

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

41-
private readonly object mutex = new object();
42+
private readonly Lock mutex = new();
4243

4344
public void Message(Message msg)
4445
{

csharp/extractor/Semmle.Util/Logging/PidStreamWriter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.IO;
2-
using System.Diagnostics;
2+
using System.Threading;
33

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

36-
private readonly object mutex = new object();
36+
private readonly Lock mutex = new();
3737
}
3838
}

csharp/extractor/Testrunner/Testrunner.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// </summary>
1515
public class Testrunner
1616
{
17-
private static readonly object ConsoleLock = new();
17+
private static readonly Lock ConsoleLock = new();
1818

1919
private static readonly ManualResetEvent Finished = new(false);
2020

0 commit comments

Comments
 (0)