Skip to content

Commit dde0281

Browse files
committed
C#: Use dedicated lock type where applicable.
1 parent 4a0875f commit dde0281

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

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

Lines changed: 2 additions & 3 deletions
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/Extractor/ExtractionContext.cs

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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)