Browse Source

use standard NETCOREAPP3_1_OR_GREATER directive

pull/1730/head
Anton Firszov 4 years ago
parent
commit
e10126e686
  1. 4
      Directory.Build.props
  2. 2
      src/ImageSharp/Memory/Allocators/Internals/Gen2GcCallback.cs
  3. 4
      src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs
  4. 2
      src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs
  5. 1
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  6. 2
      tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.Trim.cs

4
Directory.Build.props

@ -33,8 +33,4 @@
<PropertyGroup Condition="$(Configuration.StartsWith('Release')) == true">
<Optimize>true</Optimize>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','netcoreapp3.1'))">$(DefineConstants);NETCORE31COMPATIBLE</DefineConstants>
</PropertyGroup>
</Project>

2
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;

4
src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs

@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.Memory.Internals
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 @@ namespace SixLabors.ImageSharp.Memory.Internals
private bool IsHighMemoryPressure()
{
#if NETCORE31COMPATIBLE
#if NETCOREAPP3_1_OR_GREATER
GCMemoryInfo memoryInfo = GC.GetGCMemoryInfo();
return memoryInfo.MemoryLoadBytes >= memoryInfo.HighMemoryLoadThresholdBytes * this.trimSettings.HighPressureThresholdRate;
#else

2
src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs

@ -146,7 +146,7 @@ namespace SixLabors.ImageSharp.Memory
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

1
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -7,7 +7,6 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<RootNamespace>SixLabors.ImageSharp.Tests</RootNamespace>
<Configurations>Debug;Release;Debug-InnerLoop;Release-InnerLoop</Configurations>
<DefineConstants Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','netcoreapp3.1'))">$(DefineConstants);NETCORE31COMPATIBLE</DefineConstants>
</PropertyGroup>
<Choose>

2
tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.Trim.cs

@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators
}
}
#if NETCORE31COMPATIBLE
#if NETCOREAPP3_1_OR_GREATER
public static readonly bool Is32BitProcess = !Environment.Is64BitProcess;
private static readonly List<byte[]> PressureArrays = new();

Loading…
Cancel
Save