Skip to content

Commit

Permalink
Volatile.Read and Write
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach committed Sep 18, 2024
1 parent 483f6ee commit 84bbe42
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions projects/RabbitMQ.Client/client/impl/AsyncManualResetEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace RabbitMQ.Client.client.impl
sealed class AsyncManualResetEvent : IValueTaskSource
{
private ManualResetValueTaskSourceCore<bool> _valueTaskSource;
private volatile bool _isSet;
private bool _isSet;

public AsyncManualResetEvent(bool initialState = false)
{
Expand All @@ -51,7 +51,7 @@ public AsyncManualResetEvent(bool initialState = false)
}
}

public bool IsSet => _isSet;
public bool IsSet => Volatile.Read(ref _isSet);

public async ValueTask WaitAsync(CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -97,23 +97,23 @@ await tokenRegistration.DisposeAsync()

public void Set()
{
if (_isSet)
if (IsSet)
{
return;
}

_isSet = true;
Volatile.Write(ref _isSet, true);
_valueTaskSource.SetResult(true);
}

public void Reset()
{
if (!_isSet)
if (!IsSet)
{
return;
}

_isSet = false;
Volatile.Write(ref _isSet, false);
_valueTaskSource.Reset();
}

Expand Down

0 comments on commit 84bbe42

Please sign in to comment.