@@ -76,11 +76,8 @@ public abstract class ModelBase : IFullModel
76
76
private readonly object m_flowSendLock = new object ( ) ;
77
77
78
78
private ulong m_nextPubSeqNo ;
79
- // Values of this dictionary are ignored.
80
- // .NET contains no stock synchronized collections or sorted set implementation
81
- // prior to 4.0.
82
- private SynchronizedSortedList < ulong , object > m_unconfirmedSet =
83
- new SynchronizedSortedList < ulong , object > ( new SortedList < ulong , object > ( ) ) ;
79
+ private SynchronizedCollection < ulong > m_unconfirmedSet =
80
+ new SynchronizedCollection < ulong > ( ) ;
84
81
private bool m_onlyAcksReceived = true ;
85
82
86
83
public event ModelShutdownEventHandler ModelShutdown
@@ -390,11 +387,17 @@ public virtual void OnBasicNack(BasicNackEventArgs args)
390
387
protected virtual void handleAckNack ( ulong deliveryTag , bool multiple , bool isNack )
391
388
{
392
389
if ( multiple ) {
393
- for ( ulong i = ( ulong ) m_unconfirmedSet . GetKey ( 0 ) ; i <= deliveryTag ; i ++ ) {
394
- m_unconfirmedSet . Remove ( i ) ;
395
- }
390
+ lock ( m_unconfirmedSet . SyncRoot )
391
+ {
392
+ for ( ulong i = ( ulong ) m_unconfirmedSet [ 0 ] ; i <= deliveryTag ; i ++ ) {
393
+ // removes potential duplicates
394
+ while ( m_unconfirmedSet . Remove ( i ) )
395
+ { }
396
+ }
397
+ }
396
398
} else {
397
- m_unconfirmedSet . Remove ( deliveryTag ) ;
399
+ while ( m_unconfirmedSet . Remove ( deliveryTag ) )
400
+ { }
398
401
}
399
402
lock ( m_unconfirmedSet . SyncRoot ) {
400
403
m_onlyAcksReceived = m_onlyAcksReceived && ! isNack ;
@@ -1280,8 +1283,11 @@ public void BasicPublish(string exchange,
1280
1283
basicProperties = CreateBasicProperties ( ) ;
1281
1284
}
1282
1285
if ( m_nextPubSeqNo > 0 ) {
1283
- m_unconfirmedSet . Add ( m_nextPubSeqNo , null ) ;
1284
- m_nextPubSeqNo ++ ;
1286
+ lock ( m_unconfirmedSet . SyncRoot )
1287
+ {
1288
+ m_unconfirmedSet . Add ( m_nextPubSeqNo ) ;
1289
+ m_nextPubSeqNo ++ ;
1290
+ }
1285
1291
}
1286
1292
_Private_BasicPublish ( exchange ,
1287
1293
routingKey ,
0 commit comments