From e10126e686b08e4bbcfac3e311f75238a8a1e5cb Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 26 Nov 2021 20:37:47 +0100 Subject: [PATCH] use standard NETCOREAPP3_1_OR_GREATER directive --- Directory.Build.props | 4 ---- src/ImageSharp/Memory/Allocators/Internals/Gen2GcCallback.cs | 2 +- .../Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs | 4 ++-- .../Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs | 2 +- tests/ImageSharp.Tests/ImageSharp.Tests.csproj | 1 - .../Memory/Allocators/UniformUnmanagedMemoryPoolTests.Trim.cs | 2 +- 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index fd78f4f192..26b3cc5afc 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -33,8 +33,4 @@ true - - - $(DefineConstants);NETCORE31COMPATIBLE - diff --git a/src/ImageSharp/Memory/Allocators/Internals/Gen2GcCallback.cs b/src/ImageSharp/Memory/Allocators/Internals/Gen2GcCallback.cs index 3a0479359a..b0552936e7 100644 --- a/src/ImageSharp/Memory/Allocators/Internals/Gen2GcCallback.cs +++ b/src/ImageSharp/Memory/Allocators/Internals/Gen2GcCallback.cs @@ -3,7 +3,7 @@ // Port of BCL internal utility: // https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/System.Private.CoreLib/src/System/Gen2GcCallback.cs -#if NETCORE31COMPATIBLE +#if NETCOREAPP3_1_OR_GREATER using System; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; diff --git a/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs b/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs index ced91fec74..78498b7ea0 100644 --- a/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs +++ b/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs @@ -42,7 +42,7 @@ public UniformUnmanagedMemoryPool(int bufferLength, int capacity, TrimSettings t if (trimSettings.Enabled) { UpdateTimer(trimSettings, this); -#if NETCORE31COMPATIBLE +#if NETCOREAPP3_1_OR_GREATER || NETFRAMEWORK Gen2GcCallback.Register(s => ((UniformUnmanagedMemoryPool)s).Trim(), this); #endif this.lastTrimTimestamp = Stopwatch.ElapsedMilliseconds; @@ -328,7 +328,7 @@ private bool TrimLowPressure(UnmanagedMemoryHandle[] buffersLocal) private bool IsHighMemoryPressure() { -#if NETCORE31COMPATIBLE +#if NETCOREAPP3_1_OR_GREATER GCMemoryInfo memoryInfo = GC.GetGCMemoryInfo(); return memoryInfo.MemoryLoadBytes >= memoryInfo.HighMemoryLoadThresholdBytes * this.trimSettings.HighPressureThresholdRate; #else diff --git a/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs b/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs index d9734baea3..16a3cb73d1 100644 --- a/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs +++ b/src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs @@ -146,7 +146,7 @@ internal override MemoryGroup AllocateGroup( private static long GetDefaultMaxPoolSizeBytes() { -#if NETCORE31COMPATIBLE +#if NETCOREAPP3_1_OR_GREATER // On 64 bit .NET Core 3.1+, set the pool size to a portion of the total available memory. // There is a bug in GC.GetGCMemoryInfo() on .NET 5 + 32 bit, making TotalAvailableMemoryBytes unreliable: // https://github.com/dotnet/runtime/issues/55126#issuecomment-876779327 diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 6ac4923a49..471287006f 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -7,7 +7,6 @@ AnyCPU;x64;x86 SixLabors.ImageSharp.Tests Debug;Release;Debug-InnerLoop;Release-InnerLoop - $(DefineConstants);NETCORE31COMPATIBLE diff --git a/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.Trim.cs b/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.Trim.cs index 84d64c757b..75e57c62bc 100644 --- a/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.Trim.cs +++ b/tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.Trim.cs @@ -90,7 +90,7 @@ static void LeakPoolInstance() } } -#if NETCORE31COMPATIBLE +#if NETCOREAPP3_1_OR_GREATER public static readonly bool Is32BitProcess = !Environment.Is64BitProcess; private static readonly List PressureArrays = new();