Skip to content

Commit 1e748bb

Browse files
authored
Merge pull request #1977 from tyrielv/tyrielv/lock-object-migration
Replace object locks with System.Threading.Lock
2 parents db45285 + 5eeba9e commit 1e748bb

19 files changed

Lines changed: 33 additions & 23 deletions

GVFS/GVFS.Common/Database/PlaceholderTable.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
using System.Collections.Generic;
33
using System.Data;
44
using System.IO;
5+
using System.Threading;
56

67
namespace GVFS.Common.Database
78
{
89
/// <summary>
9-
/// This class is for interacting with the Placeholder table in the SQLite database
10+
/// This class is for interacting with the Placeholder tablein the SQLite database
1011
/// </summary>
1112
public class PlaceholderTable : IPlaceholderCollection
1213
{
1314
private IGVFSConnectionPool connectionPool;
14-
private object writerLock = new object();
15+
private Lock writerLock = new Lock();
1516

1617
public PlaceholderTable(IGVFSConnectionPool connectionPool)
1718
{

GVFS/GVFS.Common/Database/SparseTable.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
using System.Collections.Generic;
33
using System.Data;
44
using System.IO;
5+
using System.Threading;
56

67
namespace GVFS.Common.Database
78
{
89
public class SparseTable : ISparseCollection
910
{
1011
private IGVFSConnectionPool connectionPool;
11-
private object writerLock = new object();
12+
private Lock writerLock = new Lock();
1213

1314
public SparseTable(IGVFSConnectionPool connectionPool)
1415
{

GVFS/GVFS.Common/FileBasedCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public abstract class FileBasedCollection : IDisposable
2727
/// </summary>
2828
private readonly bool collectionAppendsDirectlyToFile;
2929

30-
private readonly object fileLock = new object();
30+
private readonly Lock fileLock = new Lock();
3131

3232
private readonly PhysicalFileSystem fileSystem;
3333
private readonly string dataDirectoryPath;

GVFS/GVFS.Common/GVFSLock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace GVFS.Common
88
{
99
public partial class GVFSLock
1010
{
11-
private readonly object acquisitionLock = new object();
11+
private readonly Lock acquisitionLock = new Lock();
1212
private readonly ITracer tracer;
1313
private readonly LockHolder currentLockHolder = new LockHolder();
1414

GVFS/GVFS.Common/Git/GitAuthentication.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
using System.Net.Http;
77
using System.Security.Cryptography.X509Certificates;
88
using System.Text;
9+
using System.Threading;
910

1011
namespace GVFS.Common.Git
1112
{
1213
public class GitAuthentication
1314
{
1415
private const double MaxBackoffSeconds = 30;
1516

16-
private readonly object gitAuthLock = new object();
17+
private readonly Lock gitAuthLock = new Lock();
1718
private readonly ICredentialStore credentialStore;
1819
private readonly string repoUrl;
1920

GVFS/GVFS.Common/Git/GitProcess.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.IO;
88
using System.Linq;
99
using System.Text;
10+
using System.Threading;
1011

1112
namespace GVFS.Common.Git
1213
{
@@ -21,14 +22,14 @@ public class GitProcess : ICredentialStore
2122
/// <summary>
2223
/// Lock taken for duration of running executingProcess.
2324
/// </summary>
24-
private object executionLock = new object();
25+
private Lock executionLock = new Lock();
2526

2627
/// <summary>
2728
/// Lock taken when changing the running state of executingProcess.
2829
///
2930
/// Can be taken within executionLock.
3031
/// </summary>
31-
private object processLock = new object();
32+
private Lock processLock = new Lock();
3233

3334
private string gitBinPath;
3435
private string workingDirectoryRoot;

GVFS/GVFS.Common/Git/LibGit2RepoInvoker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class LibGit2RepoInvoker : IDisposable
88
{
99
private readonly Func<LibGit2Repo> createRepo;
1010
private readonly ITracer tracer;
11-
private readonly object sharedRepoLock = new object();
11+
private readonly Lock sharedRepoLock = new Lock();
1212
private volatile bool disposing;
1313
private volatile int activeCallers;
1414
private LibGit2Repo sharedRepo;

GVFS/GVFS.Common/GitStatusCache.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class GitStatusCache : IDisposable
5656

5757
private volatile CacheState cacheState = CacheState.Dirty;
5858

59-
private object cacheFileLock = new object();
59+
private Lock cacheFileLock = new Lock();
6060

6161
internal static bool? TEST_EnableHydrationSummaryOverride = null;
6262

@@ -597,7 +597,7 @@ private bool TryRebuildStatusCache()
597597

598598
private bool TryDeleteStatusCacheFile()
599599
{
600-
Debug.Assert(Monitor.IsEntered(this.cacheFileLock), "Attempting to delete the git status cache file without the cacheFileLock");
600+
Debug.Assert(this.cacheFileLock.IsHeldByCurrentThread, "Attempting to delete the git status cache file without the cacheFileLock");
601601

602602
try
603603
{
@@ -635,7 +635,7 @@ private bool TryDeleteStatusCacheFile()
635635
/// <returns>True on success, False on failure</returns>
636636
private bool MoveCacheFileToFinalLocation(string tmpStatusFilePath)
637637
{
638-
Debug.Assert(Monitor.IsEntered(this.cacheFileLock), "Attempting to update the git status cache file without the cacheFileLock");
638+
Debug.Assert(this.cacheFileLock.IsHeldByCurrentThread, "Attempting to update the git status cache file without the cacheFileLock");
639639

640640
try
641641
{

GVFS/GVFS.Common/Maintenance/GitMaintenanceQueue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace GVFS.Common.Maintenance
88
{
99
public class GitMaintenanceQueue
1010
{
11-
private readonly object queueLock = new object();
11+
private readonly Lock queueLock = new Lock();
1212
private GVFSContext context;
1313
private BlockingCollection<GitMaintenanceStep> queue = new BlockingCollection<GitMaintenanceStep>();
1414
private GitMaintenanceStep currentStep;

GVFS/GVFS.Common/Maintenance/GitMaintenanceStep.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7+
using System.Threading;
78

89
namespace GVFS.Common.Maintenance
910
{
1011
public abstract class GitMaintenanceStep
1112
{
1213
public const string ObjectCacheLock = "git-maintenance-step.lock";
13-
private readonly object gitProcessLock = new object();
14+
private readonly Lock gitProcessLock = new Lock();
1415

1516
public GitMaintenanceStep(GVFSContext context, bool requireObjectCacheLock, GitProcessChecker gitProcessChecker = null)
1617
{

0 commit comments

Comments
 (0)