Skip to content

Commit

Permalink
refactor: Replace volatile field with Volatile.Read/Write operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mycroes committed Nov 30, 2023
1 parent 390f30b commit 69db2ce
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sally7/RequestExecutor/ConcurrentRequestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private class JobPool : IDisposable
{
private readonly Channel<int> _jobIdPool;
private readonly Request[] _requests;
private volatile bool _disposed;
private bool _disposed;

public JobPool(int maxNumberOfConcurrentRequests)
{
Expand All @@ -212,15 +212,15 @@ public JobPool(int maxNumberOfConcurrentRequests)

public void Dispose()
{
_disposed = true;
Volatile.Write(ref _disposed, true);
_jobIdPool.Writer.Complete();
}

public ValueTask<int> RentJobIdAsync(CancellationToken cancellationToken) => _jobIdPool.Reader.ReadAsync(cancellationToken);

public void ReturnJobId(int jobId)
{
if (!_jobIdPool.Writer.TryWrite(jobId) && !_disposed)
if (!_jobIdPool.Writer.TryWrite(jobId) && !Volatile.Read(ref _disposed))
{
Sally7Exception.ThrowFailedToReturnJobIDToPool(jobId);
}
Expand Down

0 comments on commit 69db2ce

Please sign in to comment.