Skip to content

Commit 84bbe42

Browse files
committed
Volatile.Read and Write
1 parent 483f6ee commit 84bbe42

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

projects/RabbitMQ.Client/client/impl/AsyncManualResetEvent.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace RabbitMQ.Client.client.impl
3939
sealed class AsyncManualResetEvent : IValueTaskSource
4040
{
4141
private ManualResetValueTaskSourceCore<bool> _valueTaskSource;
42-
private volatile bool _isSet;
42+
private bool _isSet;
4343

4444
public AsyncManualResetEvent(bool initialState = false)
4545
{
@@ -51,7 +51,7 @@ public AsyncManualResetEvent(bool initialState = false)
5151
}
5252
}
5353

54-
public bool IsSet => _isSet;
54+
public bool IsSet => Volatile.Read(ref _isSet);
5555

5656
public async ValueTask WaitAsync(CancellationToken cancellationToken)
5757
{
@@ -97,23 +97,23 @@ await tokenRegistration.DisposeAsync()
9797

9898
public void Set()
9999
{
100-
if (_isSet)
100+
if (IsSet)
101101
{
102102
return;
103103
}
104104

105-
_isSet = true;
105+
Volatile.Write(ref _isSet, true);
106106
_valueTaskSource.SetResult(true);
107107
}
108108

109109
public void Reset()
110110
{
111-
if (!_isSet)
111+
if (!IsSet)
112112
{
113113
return;
114114
}
115115

116-
_isSet = false;
116+
Volatile.Write(ref _isSet, false);
117117
_valueTaskSource.Reset();
118118
}
119119

0 commit comments

Comments
 (0)