Skip to content

Commit

Permalink
.NET 9 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
electricessence committed Nov 18, 2024
1 parent 1453eb9 commit 3950a90
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions Open.ChannelExtensions/Extensions.Join.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override bool TryPipeItems(bool _)
return false;

TList? batch;
lock (Buffer)
lock (SyncLock)
{
if (!source.TryRead(out batch))
return false;
Expand Down Expand Up @@ -48,7 +48,7 @@ protected override bool TryPipeItems(bool _)
return false;

Queue<T>? batch;
lock (Buffer)
lock (SyncLock)
{
if (!source.TryRead(out batch))
return false;
Expand Down Expand Up @@ -80,7 +80,7 @@ protected override bool TryPipeItems(bool _)
IMemoryOwner<T>? batch = null;
try
{
lock (Buffer)
lock (SyncLock)
{
if (!source.TryRead(out batch))
return false;
Expand Down
8 changes: 4 additions & 4 deletions Open.ChannelExtensions/Open.ChannelExtensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>8.6.0</Version>
<Version>9.0.0</Version>
<PackageReleaseNotes>Added .Merge, .PipeAsync, and .PropagateCompletion extensions.</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand Down Expand Up @@ -50,12 +50,12 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.Threading.Channels" Version="8.*" />
<PackageReference Include="System.Collections.Immutable" Version="8.*" />
<PackageReference Include="System.Threading.Channels" Version="9.*" />
<PackageReference Include="System.Collections.Immutable" Version="9.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.*" />
</ItemGroup>

<!-- Disable the nullable warnings when compiling for .NET Standard 2.0 -->
Expand Down
7 changes: 5 additions & 2 deletions Open.ChannelExtensions/Readers/BatchingChannelReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ public BatchingChannelReader<T, TBatch> WithTimeout(long millisecondsTimeout)
if (_batch is null) return this;

// Might be in the middle of a batch so we need to update the timeout.
lock (Buffer)
lock (SyncLock)
{
// Analyzer did not take into account thread safety.
#pragma warning disable CA1508 // Avoid dead conditional code
if (_batch is not null) RefreshTimeout();
#pragma warning restore CA1508 // Avoid dead conditional code
}

return this;
Expand Down Expand Up @@ -144,7 +147,7 @@ protected override bool TryPipeItems(bool flush)
if (Buffer?.Reader.Completion.IsCompleted != false)
return false;

lock (Buffer)
lock (SyncLock)
{
if (Buffer.Reader.Completion.IsCompleted) return false;

Expand Down
12 changes: 11 additions & 1 deletion Open.ChannelExtensions/Readers/BufferingChannelReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ public abstract class BufferingChannelReader<TIn, TOut> : ChannelReader<TOut>
/// </summary>
protected Channel<TOut>? Buffer { get; }

/// <summary>
/// The synchronization lock for the buffer.
/// </summary>
[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
#if NET9_0_OR_GREATER
protected readonly System.Threading.Lock SyncLock = new();
#else
protected readonly object SyncLock = new();
#endif

/// <summary>
/// Base constructor for a BufferingChannelReader.
/// </summary>
Expand All @@ -39,7 +49,7 @@ protected BufferingChannelReader(ChannelReader<TIn> source, bool singleReader, b
{
OnBeforeFinalFlush();
// Need to be sure writing is done before we continue...
lock (Buffer)
lock (SyncLock)
{
/* When the source is complete,
* we dump all remaining into the buffer
Expand Down

0 comments on commit 3950a90

Please sign in to comment.