Skip to content

Commit

Permalink
Implemented proper read lock for CopyTo span.
Browse files Browse the repository at this point in the history
  • Loading branch information
electricessence committed Jul 4, 2021
1 parent 2a749e8 commit c43ebf4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/Open.Collections.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageProjectUrl>https://github.com/Open-NET-Libraries/Open.Collections/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Open-NET-Libraries/Open.Collections/</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>2.10.3</Version>
<Version>2.11.1</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion source/Synchronized/LockSynchronizedCollectionWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </returns>
public Span<T> CopyTo(Span<T> span)
public override Span<T> CopyTo(Span<T> span)
{
lock (Sync) return InternalSource.CopyToSpan(span);
}
Expand Down
7 changes: 7 additions & 0 deletions source/Synchronized/ReadWriteSynchronizedCollectionWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ public override void Export(ICollection<T> to)
public override void CopyTo(T[] array, int arrayIndex)
=> Sync.Read(() => InternalSource.CopyTo(array, arrayIndex));

/// <inheritdoc cref="ReadOnlyCollectionWrapper{T, TCollection}.CopyTo(Span{T})"/>
public override Span<T> CopyTo(Span<T> span)
{
using var read = Sync.ReadLock();
return InternalSource.CopyToSpan(span);
}

#endregion

#region Dispose
Expand Down

0 comments on commit c43ebf4

Please sign in to comment.