Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace SemaphoreLight with SemaphoreSlim #1265

Merged
merged 2 commits into from
Dec 9, 2023
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
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Channels/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ protected IConnectionInfo ConnectionInfo
/// Gets the session semaphore to control number of session channels.
/// </summary>
/// <value>The session semaphore.</value>
protected SemaphoreLight SessionSemaphore
protected SemaphoreSlim SessionSemaphore
{
get { return _session.SessionSemaphore; }
}
Expand Down
244 changes: 0 additions & 244 deletions src/Renci.SshNet/Common/SemaphoreLight.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Renci.SshNet/ISession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal interface ISession : IDisposable
/// <value>
/// The session semaphore.
/// </value>
SemaphoreLight SessionSemaphore { get; }
SemaphoreSlim SessionSemaphore { get; }

/// <summary>
/// Gets a <see cref="WaitHandle"/> that can be used to wait for the message listener loop to complete.
Expand Down
8 changes: 4 additions & 4 deletions src/Renci.SshNet/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class Session : ISession
/// <remarks>
/// Some server may restrict number to prevent authentication attacks.
/// </remarks>
private static readonly SemaphoreLight AuthenticationConnection = new SemaphoreLight(3);
private static readonly SemaphoreSlim AuthenticationConnection = new SemaphoreSlim(3);

/// <summary>
/// Holds the factory to use for creating new services.
Expand Down Expand Up @@ -196,7 +196,7 @@ public class Session : ISession

private Compressor _clientCompression;

private SemaphoreLight _sessionSemaphore;
private SemaphoreSlim _sessionSemaphore;

private bool _isDisconnectMessageSent;

Expand All @@ -213,15 +213,15 @@ public class Session : ISession
/// <value>
/// The session semaphore.
/// </value>
public SemaphoreLight SessionSemaphore
public SemaphoreSlim SessionSemaphore
{
get
{
if (_sessionSemaphore is null)
{
lock (_connectAndLazySemaphoreInitLock)
{
_sessionSemaphore ??= new SemaphoreLight(ConnectionInfo.MaxSessions);
_sessionSemaphore ??= new SemaphoreSlim(ConnectionInfo.MaxSessions);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Renci.SshNet/Sftp/SftpFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal sealed class SftpFileReader : ISftpFileReader
private readonly byte[] _handle;
private readonly ISftpSession _sftpSession;
private readonly uint _chunkSize;
private readonly SemaphoreLight _semaphore;
private readonly SemaphoreSlim _semaphore;
private readonly object _readLock;
private readonly ManualResetEvent _disposingWaitHandle;
private readonly ManualResetEvent _readAheadCompleted;
Expand Down Expand Up @@ -62,7 +62,7 @@ public SftpFileReader(byte[] handle, ISftpSession sftpSession, uint chunkSize, i
_sftpSession = sftpSession;
_chunkSize = chunkSize;
_fileSize = fileSize;
_semaphore = new SemaphoreLight(maxPendingReads);
_semaphore = new SemaphoreSlim(maxPendingReads);
_queue = new Dictionary<int, BufferedRead>(maxPendingReads);
_readLock = new object();
_readAheadCompleted = new ManualResetEvent(initialState: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ChannelSessionTest_Dispose_Disposed : ChannelSessionTestBase
private uint _remotePacketSize;
private uint _remoteChannelNumber;
private TimeSpan _channelCloseTimeout;
private SemaphoreLight _sessionSemaphore;
private SemaphoreSlim _sessionSemaphore;
private IList<ChannelEventArgs> _channelClosedRegister;
private List<ExceptionEventArgs> _channelExceptionRegister;

Expand All @@ -38,7 +38,7 @@ protected override void SetupData()
_remoteWindowSize = (uint)random.Next(0, int.MaxValue);
_remotePacketSize = (uint)random.Next(100, 200);
_channelCloseTimeout = TimeSpan.FromSeconds(random.Next(10, 20));
_sessionSemaphore = new SemaphoreLight(1);
_sessionSemaphore = new SemaphoreSlim(1);
_channelClosedRegister = new List<ChannelEventArgs>();
_channelExceptionRegister = new List<ExceptionEventArgs>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_Chann
private List<ExceptionEventArgs> _channelExceptionRegister;
private ChannelSession _channel;
private MockSequence _sequence;
private SemaphoreLight _sessionSemaphore;
private SemaphoreSlim _sessionSemaphore;
private int _initialSessionSemaphoreCount;

protected override void SetupData()
Expand All @@ -41,7 +41,7 @@ protected override void SetupData()
_channelClosedRegister = new List<ChannelEventArgs>();
_channelExceptionRegister = new List<ExceptionEventArgs>();
_initialSessionSemaphoreCount = random.Next(10, 20);
_sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount);
_sessionSemaphore = new SemaphoreSlim(_initialSessionSemaphoreCount);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_Chann
private List<ExceptionEventArgs> _channelExceptionRegister;
private ChannelSession _channel;
private MockSequence _sequence;
private SemaphoreLight _sessionSemaphore;
private SemaphoreSlim _sessionSemaphore;
private int _initialSessionSemaphoreCount;

protected override void SetupData()
Expand All @@ -38,7 +38,7 @@ protected override void SetupData()
_channelClosedRegister = new List<ChannelEventArgs>();
_channelExceptionRegister = new List<ExceptionEventArgs>();
_initialSessionSemaphoreCount = random.Next(10, 20);
_sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount);
_sessionSemaphore = new SemaphoreSlim(_initialSessionSemaphoreCount);
}

protected override void SetupMocks()
Expand Down Expand Up @@ -126,4 +126,4 @@ public void IsOpenShouldReturnFalse()
Assert.IsFalse(_channel.IsOpen);
}
}
}
}
Loading