Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/MappedFileQueues/CrossPlatformProcessLock.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1416 // Ignore: Validate platform compatibility

using System.Runtime.InteropServices;
using System.Security.Cryptography;

Expand All @@ -7,7 +9,7 @@ namespace MappedFileQueues;
/// A cross-platform process lock implementation. Only Windows and Linux are supported.
/// On Windows, a named mutex is used. On Linux, a file lock is used. On other platforms, a no-op lock is used.
/// </summary>
internal sealed class CrossPlatformProcessLock : IDisposable
internal sealed class CrossPlatformProcessLock
{
private readonly IProcessLock _lock;

Expand Down Expand Up @@ -39,11 +41,9 @@ public CrossPlatformProcessLock(string name, string storePath)
public void Acquire() => _lock.Acquire();
public void Release() => _lock.Release();

public void Dispose() => _lock.Dispose();

#region Process Lock Interface

private interface IProcessLock : IDisposable
private interface IProcessLock
{
void Acquire();
void Release();
Expand Down Expand Up @@ -71,8 +71,6 @@ public void Release()
_mutex?.ReleaseMutex();
_mutex?.Dispose();
}

public void Dispose() => Release();
}

#endregion
Expand Down Expand Up @@ -107,8 +105,6 @@ public void Release()
_lockFileStream?.Unlock(0, 0);
_lockFileStream?.Dispose();
}

public void Dispose() => Release();
}

#endregion
Expand All @@ -124,10 +120,6 @@ public void Acquire()
public void Release()
{
}

public void Dispose()
{
}
}

#endregion
Expand Down
6 changes: 3 additions & 3 deletions src/MappedFileQueues/MappedFileQueueT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public void Dispose()
private void RecoverProducerOffsetIfNeeded()
{
var lockName = "recovery_lock";
using var processLock = new CrossPlatformProcessLock(lockName, _options.StorePath);

processLock.Acquire();
var processLock = new CrossPlatformProcessLock(lockName, _options.StorePath);

try
{
processLock.Acquire();

var consumer = Consumer;

if (consumer.NextMessageAvailable())
Expand Down