@@ -44,7 +44,7 @@ internal abstract class ConsumerDispatcherChannelBase : ConsumerDispatcherBase,
44
44
private readonly System . Threading . Channels . ChannelWriter < WorkStruct > _writer ;
45
45
private readonly Task _worker ;
46
46
private readonly ushort _concurrency ;
47
- private bool _quiesce = false ;
47
+ private long _isQuiescing ;
48
48
private bool _disposed ;
49
49
50
50
internal ConsumerDispatcherChannelBase ( Impl . Channel channel , ushort concurrency )
@@ -79,15 +79,15 @@ internal ConsumerDispatcherChannelBase(Impl.Channel channel, ushort concurrency)
79
79
}
80
80
}
81
81
82
- public bool IsShutdown => _quiesce ;
82
+ public bool IsShutdown => IsQuiescing ;
83
83
84
84
public ushort Concurrency => _concurrency ;
85
85
86
86
public async ValueTask HandleBasicConsumeOkAsync ( IAsyncBasicConsumer consumer , string consumerTag , CancellationToken cancellationToken )
87
87
{
88
88
cancellationToken . ThrowIfCancellationRequested ( ) ;
89
89
90
- if ( false == _disposed && false == _quiesce )
90
+ if ( false == _disposed && false == IsQuiescing )
91
91
{
92
92
try
93
93
{
@@ -110,7 +110,7 @@ public async ValueTask HandleBasicDeliverAsync(string consumerTag, ulong deliver
110
110
{
111
111
cancellationToken . ThrowIfCancellationRequested ( ) ;
112
112
113
- if ( false == _disposed && false == _quiesce )
113
+ if ( false == _disposed && false == IsQuiescing )
114
114
{
115
115
IAsyncBasicConsumer consumer = GetConsumerOrDefault ( consumerTag ) ;
116
116
var work = WorkStruct . CreateDeliver ( consumer , consumerTag , deliveryTag , redelivered , exchange , routingKey , basicProperties , body ) ;
@@ -123,7 +123,7 @@ public async ValueTask HandleBasicCancelOkAsync(string consumerTag, Cancellation
123
123
{
124
124
cancellationToken . ThrowIfCancellationRequested ( ) ;
125
125
126
- if ( false == _disposed && false == _quiesce )
126
+ if ( false == _disposed && false == IsQuiescing )
127
127
{
128
128
IAsyncBasicConsumer consumer = GetAndRemoveConsumer ( consumerTag ) ;
129
129
WorkStruct work = WorkStruct . CreateCancelOk ( consumer , consumerTag ) ;
@@ -136,7 +136,7 @@ public async ValueTask HandleBasicCancelAsync(string consumerTag, CancellationTo
136
136
{
137
137
cancellationToken . ThrowIfCancellationRequested ( ) ;
138
138
139
- if ( false == _disposed && false == _quiesce )
139
+ if ( false == _disposed && false == IsQuiescing )
140
140
{
141
141
IAsyncBasicConsumer consumer = GetAndRemoveConsumer ( consumerTag ) ;
142
142
WorkStruct work = WorkStruct . CreateCancel ( consumer , consumerTag ) ;
@@ -147,7 +147,7 @@ await _writer.WriteAsync(work, cancellationToken)
147
147
148
148
public void Quiesce ( )
149
149
{
150
- _quiesce = true ;
150
+ Interlocked . Exchange ( ref _isQuiescing , 1 ) ;
151
151
}
152
152
153
153
public async Task WaitForShutdownAsync ( )
@@ -157,7 +157,7 @@ public async Task WaitForShutdownAsync()
157
157
return ;
158
158
}
159
159
160
- if ( _quiesce )
160
+ if ( IsQuiescing )
161
161
{
162
162
try
163
163
{
@@ -193,6 +193,19 @@ await _worker
193
193
}
194
194
}
195
195
196
+ protected bool IsQuiescing
197
+ {
198
+ get
199
+ {
200
+ if ( Interlocked . Read ( ref _isQuiescing ) == 1 )
201
+ {
202
+ return true ;
203
+ }
204
+
205
+ return false ;
206
+ }
207
+ }
208
+
196
209
protected sealed override void ShutdownConsumer ( IAsyncBasicConsumer consumer , ShutdownEventArgs reason )
197
210
{
198
211
_writer . TryWrite ( WorkStruct . CreateShutdown ( consumer , reason ) ) ;
0 commit comments