Avoid some full memory barriers (#1590)

* Avoid some full memory barriers

* Reset in stats itself

* Updated MqttClientStatistics

* Fixed order of members as artifact from merge-conflict
This commit is contained in:
Günther Foidl
2023-01-19 20:08:51 +01:00
committed by GitHub
parent ead58dd606
commit b98417ab39
4 changed files with 63 additions and 33 deletions
+14
View File
@@ -22,7 +22,11 @@ namespace MQTTnet.Internal
public void Clear()
{
#if NETCOREAPP3_1_OR_GREATER
_queue.Clear();
#else
Interlocked.Exchange(ref _queue, new ConcurrentQueue<TItem>());
#endif
}
public void Dispose()
@@ -32,6 +36,16 @@ namespace MQTTnet.Internal
_signal.Dispose();
_isDisposed = true;
#if !NETSTANDARD1_3
if (typeof(IDisposable).IsAssignableFrom(typeof(TItem)))
{
while (_queue.TryDequeue(out TItem item))
{
(item as IDisposable).Dispose();
}
}
#endif
}
}