Skip to content

Commit aaee0cf

Browse files
Switch unconfirmed set to use SynchronizedCollection
Unfortunately, there is no synchronized set in .NET 3.0, so we use explicit locking to ensure element uniqueness.
1 parent 3e3196f commit aaee0cf

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

projects/client/RabbitMQ.Client/RabbitMQ.Client.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
<Reference Include="System.Data" />
138138
<Reference Include="System.Xml" />
139139
<Reference Include="System.Configuration" />
140+
<Reference Include="System.ServiceModel" />
140141
</ItemGroup>
141142

142143
<!-- Mono compatibility workarounds -->

projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,8 @@ public abstract class ModelBase : IFullModel
7676
private readonly object m_flowSendLock = new object();
7777

7878
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>();
8481
private bool m_onlyAcksReceived = true;
8582

8683
public event ModelShutdownEventHandler ModelShutdown
@@ -390,11 +387,17 @@ public virtual void OnBasicNack(BasicNackEventArgs args)
390387
protected virtual void handleAckNack(ulong deliveryTag, bool multiple, bool isNack)
391388
{
392389
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+
}
396398
} else {
397-
m_unconfirmedSet.Remove(deliveryTag);
399+
while(m_unconfirmedSet.Remove(deliveryTag))
400+
{}
398401
}
399402
lock (m_unconfirmedSet.SyncRoot) {
400403
m_onlyAcksReceived = m_onlyAcksReceived && !isNack;
@@ -1280,8 +1283,11 @@ public void BasicPublish(string exchange,
12801283
basicProperties = CreateBasicProperties();
12811284
}
12821285
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+
}
12851291
}
12861292
_Private_BasicPublish(exchange,
12871293
routingKey,

0 commit comments

Comments
 (0)