Skip to content

Commit 3950a90

Browse files
.NET 9 upgrade
1 parent 1453eb9 commit 3950a90

File tree

7 files changed

+26
-13
lines changed

7 files changed

+26
-13
lines changed

Open.ChannelExtensions.Benchmarks/Open.ChannelExtensions.Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

Open.ChannelExtensions.ComparisonTests/Open.ChannelExtensions.ComparisonTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

Open.ChannelExtensions.Tests/Open.ChannelExtensions.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<LangVersion>latest</LangVersion>
77
<IsPackable>false</IsPackable>
88
</PropertyGroup>

Open.ChannelExtensions/Extensions.Join.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected override bool TryPipeItems(bool _)
1818
return false;
1919

2020
TList? batch;
21-
lock (Buffer)
21+
lock (SyncLock)
2222
{
2323
if (!source.TryRead(out batch))
2424
return false;
@@ -48,7 +48,7 @@ protected override bool TryPipeItems(bool _)
4848
return false;
4949

5050
Queue<T>? batch;
51-
lock (Buffer)
51+
lock (SyncLock)
5252
{
5353
if (!source.TryRead(out batch))
5454
return false;
@@ -80,7 +80,7 @@ protected override bool TryPipeItems(bool _)
8080
IMemoryOwner<T>? batch = null;
8181
try
8282
{
83-
lock (Buffer)
83+
lock (SyncLock)
8484
{
8585
if (!source.TryRead(out batch))
8686
return false;

Open.ChannelExtensions/Open.ChannelExtensions.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<RepositoryType>git</RepositoryType>
2323
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2424
<GenerateDocumentationFile>true</GenerateDocumentationFile>
25-
<Version>8.6.0</Version>
25+
<Version>9.0.0</Version>
2626
<PackageReleaseNotes>Added .Merge, .PipeAsync, and .PropagateCompletion extensions.</PackageReleaseNotes>
2727
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2828
<PublishRepositoryUrl>true</PublishRepositoryUrl>
@@ -50,12 +50,12 @@
5050
</ItemGroup>
5151

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

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

6161
<!-- Disable the nullable warnings when compiling for .NET Standard 2.0 -->

Open.ChannelExtensions/Readers/BatchingChannelReader.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ public BatchingChannelReader<T, TBatch> WithTimeout(long millisecondsTimeout)
7676
if (_batch is null) return this;
7777

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

8487
return this;
@@ -144,7 +147,7 @@ protected override bool TryPipeItems(bool flush)
144147
if (Buffer?.Reader.Completion.IsCompleted != false)
145148
return false;
146149

147-
lock (Buffer)
150+
lock (SyncLock)
148151
{
149152
if (Buffer.Reader.Completion.IsCompleted) return false;
150153

Open.ChannelExtensions/Readers/BufferingChannelReader.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ public abstract class BufferingChannelReader<TIn, TOut> : ChannelReader<TOut>
1717
/// </summary>
1818
protected Channel<TOut>? Buffer { get; }
1919

20+
/// <summary>
21+
/// The synchronization lock for the buffer.
22+
/// </summary>
23+
[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
24+
#if NET9_0_OR_GREATER
25+
protected readonly System.Threading.Lock SyncLock = new();
26+
#else
27+
protected readonly object SyncLock = new();
28+
#endif
29+
2030
/// <summary>
2131
/// Base constructor for a BufferingChannelReader.
2232
/// </summary>
@@ -39,7 +49,7 @@ protected BufferingChannelReader(ChannelReader<TIn> source, bool singleReader, b
3949
{
4050
OnBeforeFinalFlush();
4151
// Need to be sure writing is done before we continue...
42-
lock (Buffer)
52+
lock (SyncLock)
4353
{
4454
/* When the source is complete,
4555
* we dump all remaining into the buffer

0 commit comments

Comments
 (0)