From c43ebf4062aea70a42259d05b13ea76dcab7df6d Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Sun, 4 Jul 2021 11:39:28 -0700 Subject: [PATCH] Implemented proper read lock for CopyTo span. --- source/Open.Collections.csproj | 2 +- source/Synchronized/LockSynchronizedCollectionWrapper.cs | 2 +- .../Synchronized/ReadWriteSynchronizedCollectionWrapper.cs | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/Open.Collections.csproj b/source/Open.Collections.csproj index 972d1e0..c6782ca 100644 --- a/source/Open.Collections.csproj +++ b/source/Open.Collections.csproj @@ -17,7 +17,7 @@ https://github.com/Open-NET-Libraries/Open.Collections/ https://github.com/Open-NET-Libraries/Open.Collections/ git - 2.10.3 + 2.11.1 MIT true diff --git a/source/Synchronized/LockSynchronizedCollectionWrapper.cs b/source/Synchronized/LockSynchronizedCollectionWrapper.cs index 4191002..2f16a90 100644 --- a/source/Synchronized/LockSynchronizedCollectionWrapper.cs +++ b/source/Synchronized/LockSynchronizedCollectionWrapper.cs @@ -119,7 +119,7 @@ public override void CopyTo(T[] array, int arrayIndex) /// If the count was less than the target length, a new span representing the results. /// Otherwise the target is returned. /// - public Span CopyTo(Span span) + public override Span CopyTo(Span span) { lock (Sync) return InternalSource.CopyToSpan(span); } diff --git a/source/Synchronized/ReadWriteSynchronizedCollectionWrapper.cs b/source/Synchronized/ReadWriteSynchronizedCollectionWrapper.cs index bd6c8a3..d573cad 100644 --- a/source/Synchronized/ReadWriteSynchronizedCollectionWrapper.cs +++ b/source/Synchronized/ReadWriteSynchronizedCollectionWrapper.cs @@ -78,6 +78,13 @@ public override void Export(ICollection to) public override void CopyTo(T[] array, int arrayIndex) => Sync.Read(() => InternalSource.CopyTo(array, arrayIndex)); + /// + public override Span CopyTo(Span span) + { + using var read = Sync.ReadLock(); + return InternalSource.CopyToSpan(span); + } + #endregion #region Dispose