Skip to content

Commit c43ebf4

Browse files
Implemented proper read lock for CopyTo span.
1 parent 2a749e8 commit c43ebf4

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

source/Open.Collections.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PackageProjectUrl>https://github.com/Open-NET-Libraries/Open.Collections/</PackageProjectUrl>
1818
<RepositoryUrl>https://github.com/Open-NET-Libraries/Open.Collections/</RepositoryUrl>
1919
<RepositoryType>git</RepositoryType>
20-
<Version>2.10.3</Version>
20+
<Version>2.11.1</Version>
2121
<PackageReleaseNotes></PackageReleaseNotes>
2222
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2323
<PublishRepositoryUrl>true</PublishRepositoryUrl>

source/Synchronized/LockSynchronizedCollectionWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public override void CopyTo(T[] array, int arrayIndex)
119119
/// If the count was less than the target length, a new span representing the results.
120120
/// Otherwise the target is returned.
121121
/// </returns>
122-
public Span<T> CopyTo(Span<T> span)
122+
public override Span<T> CopyTo(Span<T> span)
123123
{
124124
lock (Sync) return InternalSource.CopyToSpan(span);
125125
}

source/Synchronized/ReadWriteSynchronizedCollectionWrapper.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public override void Export(ICollection<T> to)
7878
public override void CopyTo(T[] array, int arrayIndex)
7979
=> Sync.Read(() => InternalSource.CopyTo(array, arrayIndex));
8080

81+
/// <inheritdoc cref="ReadOnlyCollectionWrapper{T, TCollection}.CopyTo(Span{T})"/>
82+
public override Span<T> CopyTo(Span<T> span)
83+
{
84+
using var read = Sync.ReadLock();
85+
return InternalSource.CopyToSpan(span);
86+
}
87+
8188
#endregion
8289

8390
#region Dispose

0 commit comments

Comments
 (0)