Imported Upstream version 5.16.0.100

Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-08-07 15:19:03 +00:00
parent 0a9828183b
commit 7d7f676260
4419 changed files with 170950 additions and 90273 deletions

View File

@@ -1,90 +1,50 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27108.1
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{F19CC87B-3230-42BF-8C1F-88F4F5EDE153}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Caching.Tests", "tests\System.Runtime.Caching.Tests.csproj", "{397E49A7-EB26-4368-8F46-D78B98F4A971}"
ProjectSection(ProjectDependencies) = postProject
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829} = {A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Caching", "src\System.Runtime.Caching.csproj", "{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}"
ProjectSection(ProjectDependencies) = postProject
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280} = {3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Caching", "ref\System.Runtime.Caching.csproj", "{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9EC38C79-BC41-4675-AB3D-A509BDC14FE0}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{1A2F9F4A-A032-433E-B914-ADD5992BB178}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Caching", "src\System.Runtime.Caching.csproj", "{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E107E9C1-E893-4E87-987E-04EF0DCEAEFD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{D4DA8C10-76FA-49D3-B4F2-BCB0C94330F6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Caching.Tests", "tests\System.Runtime.Caching.Tests.csproj", "{397E49A7-EB26-4368-8F46-D78B98F4A971}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{2E666815-2EDB-464B-9DF6-380BF4789AD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
netcoreapp-Windows_NT-Debug|Any CPU = netcoreapp-Windows_NT-Debug|Any CPU
netcoreapp-Windows_NT-Release|Any CPU = netcoreapp-Windows_NT-Release|Any CPU
netfx-Debug|Any CPU = netfx-Debug|Any CPU
netfx-Release|Any CPU = netfx-Release|Any CPU
netstandard-Debug|Any CPU = netstandard-Debug|Any CPU
netstandard-Release|Any CPU = netstandard-Release|Any CPU
netstandard-Windows_NT-Debug|Any CPU = netstandard-Windows_NT-Debug|Any CPU
netstandard-Windows_NT-Release|Any CPU = netstandard-Windows_NT-Release|Any CPU
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netcoreapp-Windows_NT-Debug|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netcoreapp-Windows_NT-Debug|Any CPU.Build.0 = netstandard-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netcoreapp-Windows_NT-Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netcoreapp-Windows_NT-Release|Any CPU.Build.0 = netstandard-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netfx-Debug|Any CPU.ActiveCfg = netfx-Debug|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netfx-Debug|Any CPU.Build.0 = netfx-Debug|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netfx-Release|Any CPU.ActiveCfg = netfx-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netfx-Release|Any CPU.Build.0 = netfx-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netstandard-Debug|Any CPU.ActiveCfg = netstandard-Debug|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netstandard-Debug|Any CPU.Build.0 = netstandard-Debug|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netstandard-Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netstandard-Release|Any CPU.Build.0 = netstandard-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netstandard-Windows_NT-Debug|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netstandard-Windows_NT-Debug|Any CPU.Build.0 = netstandard-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netstandard-Windows_NT-Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.netstandard-Windows_NT-Release|Any CPU.Build.0 = netstandard-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netcoreapp-Windows_NT-Debug|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netcoreapp-Windows_NT-Debug|Any CPU.Build.0 = netstandard-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netcoreapp-Windows_NT-Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netcoreapp-Windows_NT-Release|Any CPU.Build.0 = netstandard-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netfx-Debug|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netfx-Debug|Any CPU.Build.0 = netstandard-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netfx-Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netfx-Release|Any CPU.Build.0 = netstandard-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netstandard-Debug|Any CPU.ActiveCfg = netstandard-Debug|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netstandard-Debug|Any CPU.Build.0 = netstandard-Debug|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netstandard-Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netstandard-Release|Any CPU.Build.0 = netstandard-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netstandard-Windows_NT-Debug|Any CPU.ActiveCfg = netstandard-Windows_NT-Debug|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netstandard-Windows_NT-Debug|Any CPU.Build.0 = netstandard-Windows_NT-Debug|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netstandard-Windows_NT-Release|Any CPU.ActiveCfg = netstandard-Windows_NT-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.netstandard-Windows_NT-Release|Any CPU.Build.0 = netstandard-Windows_NT-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netcoreapp-Windows_NT-Debug|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netcoreapp-Windows_NT-Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netcoreapp-Windows_NT-Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netcoreapp-Windows_NT-Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netfx-Debug|Any CPU.ActiveCfg = netfx-Debug|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netfx-Debug|Any CPU.Build.0 = netfx-Debug|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netfx-Release|Any CPU.ActiveCfg = netfx-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netfx-Release|Any CPU.Build.0 = netfx-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netstandard-Debug|Any CPU.ActiveCfg = netfx-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netstandard-Debug|Any CPU.Build.0 = netfx-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netstandard-Release|Any CPU.ActiveCfg = netfx-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netstandard-Release|Any CPU.Build.0 = netfx-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netstandard-Windows_NT-Debug|Any CPU.ActiveCfg = netfx-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netstandard-Windows_NT-Debug|Any CPU.Build.0 = netfx-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netstandard-Windows_NT-Release|Any CPU.ActiveCfg = netfx-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.netstandard-Windows_NT-Release|Any CPU.Build.0 = netfx-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.Debug|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
{397E49A7-EB26-4368-8F46-D78B98F4A971}.Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.Debug|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829}.Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.Debug|Any CPU.ActiveCfg = netstandard-Debug|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.Debug|Any CPU.Build.0 = netstandard-Debug|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280}.Release|Any CPU.Build.0 = netstandard-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280} = {F19CC87B-3230-42BF-8C1F-88F4F5EDE153}
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829} = {9EC38C79-BC41-4675-AB3D-A509BDC14FE0}
{397E49A7-EB26-4368-8F46-D78B98F4A971} = {D4DA8C10-76FA-49D3-B4F2-BCB0C94330F6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D3D6D992-CDEE-4C0C-83A6-E2EF77383E5C}
{397E49A7-EB26-4368-8F46-D78B98F4A971} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{A7B6FB6E-F484-42D7-8A5E-F7D0DCC03829} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD}
{3B7A97BD-F4DC-4FF9-AB6D-3B714E5D9280} = {2E666815-2EDB-464B-9DF6-380BF4789AD4}
EndGlobalSection
EndGlobal

View File

@@ -3,7 +3,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<ProjectReference Include="..\ref\System.Runtime.Caching.csproj">
<SupportedFramework>netcoreapp2.0;net45;$(AllXamarinFrameworks)</SupportedFramework>
<SupportedFramework>uap10.0.16299;netcoreapp2.0;net45;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.Runtime.Caching.csproj" />
<InboxOnTargetFramework Include="net45">

View File

@@ -4,10 +4,12 @@
<PackageConfigurations>
netstandard;
netcoreapp2.0-Windows_NT;
netcoreapp2.0-Unix;
</PackageConfigurations>
<BuildConfigurations>
$(PackageConfigurations);
netcoreapp-Windows_NT;
netcoreapp-Unix;
_netfx;
</BuildConfigurations>
</PropertyGroup>

View File

@@ -183,4 +183,7 @@
<data name="PlatformNotSupported_Caching" xml:space="preserve">
<value>System.Runtime.Caching is not supported on this platform.</value>
</data>
<data name="PlatformNotSupported_PhysicalMemoryLimitPercentage" xml:space="preserve">
<value>The PhysicalMemoryLimitPercentage parameter is not supported on this platform.</value>
</data>
</root>

View File

@@ -7,15 +7,19 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- Although we have a netstandard configuration, we know we are not currently UAP compatible-->
<UWPCompatible>false</UWPCompatible>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsWindows)' != 'true'">SR.PlatformNotSupported_Caching</GeneratePlatformNotSupportedAssemblyMessage>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetGroup)' == 'netstandard'">SR.PlatformNotSupported_Caching</GeneratePlatformNotSupportedAssemblyMessage>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Unix-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Unix-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp2.0-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<ItemGroup Condition="'$(TargetGroup)' != 'netstandard'">
<Compile Include="System\Runtime\Caching\_shims.cs" />
<Compile Include="System\Runtime\Caching\CacheEntryChangeMonitor.cs" />
<Compile Include="System\Runtime\Caching\CacheEntryRemovedArguments.cs" />
@@ -59,6 +63,10 @@
<Compile Include="System\Runtime\Caching\Hosting\IFileChangeNotificationSystem.cs" />
<Compile Include="System\Runtime\Caching\Hosting\IMemoryCacheManager.cs" />
<Compile Include="System\Runtime\Caching\Resources\RH.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<Compile Include="System\Runtime\Caching\MemoryMonitor.Windows.cs" />
<Compile Include="System\Runtime\Caching\PhysicalMemoryMonitor.Windows.cs" />
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.GlobalMemoryStatusEx.cs">
<Link>Common\Interop\Windows\kernel32\Interop.GlobalMemoryStatusEx.cs</Link>
</Compile>
@@ -69,6 +77,9 @@
<Link>Common\Interop\Windows\Interop.Libraries.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
<Compile Include="System\Runtime\Caching\PhysicalMemoryMonitor.Unix.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Win32.Primitives" />
<Reference Include="Microsoft.Win32.Registry" />
@@ -90,6 +101,7 @@
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation" />
<Reference Include="System.Security.Permissions" />
<Reference Include="System.Security.Principal.Windows" />
<Reference Include="System.Threading" />

View File

@@ -7,7 +7,7 @@ using System.Configuration;
namespace System.Runtime.Caching.Configuration
{
public sealed class CachingSectionGroup : ConfigurationSectionGroup
internal sealed class CachingSectionGroup : ConfigurationSectionGroup
{
public CachingSectionGroup()
{

View File

@@ -8,7 +8,7 @@ using System.Configuration;
namespace System.Runtime.Caching.Configuration
{
public sealed class MemoryCacheElement : ConfigurationElement
internal sealed class MemoryCacheElement : ConfigurationElement
{
private static ConfigurationPropertyCollection s_properties;
private static readonly ConfigurationProperty s_propName;

View File

@@ -21,7 +21,7 @@ namespace System.Runtime.Caching.Configuration
</system.caching>
*/
public sealed class MemoryCacheSection : ConfigurationSection
internal sealed class MemoryCacheSection : ConfigurationSection
{
private static ConfigurationPropertyCollection s_properties;
private static readonly ConfigurationProperty s_propNamedCaches;

View File

@@ -9,7 +9,7 @@ namespace System.Runtime.Caching.Configuration
{
[ConfigurationCollection(typeof(MemoryCacheElement),
CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
public sealed class MemoryCacheSettingsCollection : ConfigurationElementCollection
internal sealed class MemoryCacheSettingsCollection : ConfigurationElementCollection
{
private static ConfigurationPropertyCollection s_properties;

View File

@@ -413,29 +413,35 @@ namespace System.Runtime.Caching
}
private static void MonitorRegistryForOneChange() {
// Close the open reg handle
if (s_regHandle != null) {
s_regHandle.Close();
s_regHandle = null;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Close the open reg handle
if (s_regHandle != null)
{
s_regHandle.Close();
s_regHandle = null;
}
// Open the reg key
int result = NativeMethods.RegOpenKeyEx(NativeMethods.HKEY_LOCAL_MACHINE, s_listenKeyName, 0, NativeMethods.KEY_READ, out s_regHandle);
if (result != 0) {
StopRegistryMonitor();
return;
}
// Open the reg key
int result = NativeMethods.RegOpenKeyEx(NativeMethods.HKEY_LOCAL_MACHINE, s_listenKeyName, 0, NativeMethods.KEY_READ, out s_regHandle);
if (result != 0)
{
StopRegistryMonitor();
return;
}
// Listen for changes.
result = NativeMethods.RegNotifyChangeKeyValue(
s_regHandle,
true,
NativeMethods.REG_NOTIFY_CHANGE_NAME | NativeMethods.REG_NOTIFY_CHANGE_LAST_SET,
s_notifyEvent.SafeWaitHandle,
true);
// Listen for changes.
result = NativeMethods.RegNotifyChangeKeyValue(
s_regHandle,
true,
NativeMethods.REG_NOTIFY_CHANGE_NAME | NativeMethods.REG_NOTIFY_CHANGE_LAST_SET,
s_notifyEvent.SafeWaitHandle,
true);
if (result != 0) {
StopRegistryMonitor();
if (result != 0)
{
StopRegistryMonitor();
}
}
}
@@ -523,8 +529,11 @@ namespace System.Runtime.Caching
}
else {
if (s_includeThreadPrefix) {
idThread = NativeMethods.GetCurrentThreadId();
idProcess = NativeMethods.GetCurrentProcessId();
idThread = Thread.CurrentThread.ManagedThreadId;
using(var process = Process.GetCurrentProcess())
{
idProcess = process.Id;
}
traceFormat = "[0x{0:x}.{1:x} {2} {3}] {4}\n{5}";
}
else {
@@ -610,6 +619,11 @@ Stack trace:
A=Exit process R=Debug I=Continue";
}
int idProcess = 0;
using (var process = Process.GetCurrentProcess())
{
idProcess = process.Id;
}
string dialogMessage = string.Format(
CultureInfo.InvariantCulture,
@@ -617,35 +631,9 @@ A=Exit process R=Debug I=Continue";
message,
fileName, lineNumber,
COMPONENT,
NativeMethods.GetCurrentProcessId(), NativeMethods.GetCurrentThreadId(),
idProcess, Thread.CurrentThread.ManagedThreadId,
trace.ToString());
//MBResult mbResult = new MBResult();
//Thread thread = new Thread(
// delegate() {
// for (int i = 0; i < 100; i++) {
// NativeMethods.MSG msg = new NativeMethods.MSG();
// NativeMethods.PeekMessage(ref msg, new HandleRef(mbResult, IntPtr.Zero), 0, 0, NativeMethods.PM_REMOVE);
// }
// mbResult.Result = NativeMethods.MessageBox(new HandleRef(mbResult, IntPtr.Zero), dialogMessage, PRODUCT + " Assertion",
// NativeMethods.MB_SERVICE_NOTIFICATION |
// NativeMethods.MB_TOPMOST |
// NativeMethods.MB_ABORTRETRYIGNORE |
// NativeMethods.MB_ICONEXCLAMATION);
// }
//);
//thread.Start();
//thread.Join();
//if (mbResult.Result == NativeMethods.IDABORT) {
// IntPtr currentProcess = NativeMethods.GetCurrentProcess();
// NativeMethods.TerminateProcess(new HandleRef(mbResult, currentProcess), 1);
//}
//return mbResult.Result == NativeMethods.IDRETRY;
Debug.Fail(dialogMessage);
return true;
}
@@ -826,13 +814,16 @@ A=Exit process R=Debug I=Continue";
internal static void Break()
{
#if DEBUG
if (NativeMethods.IsDebuggerPresent()) {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && NativeMethods.IsDebuggerPresent())
{
NativeMethods.DebugBreak();
}
else if (!Debugger.IsAttached) {
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !Debugger.IsAttached)
{
Debugger.Launch();
}
else {
else
{
Debugger.Break();
}
#endif

View File

@@ -147,6 +147,10 @@ namespace System.Runtime.Caching
_configCacheMemoryLimitMegabytes = ConfigUtil.GetIntValue(config, ConfigUtil.CacheMemoryLimitMegabytes, _configCacheMemoryLimitMegabytes, true, Int32.MaxValue);
_configPhysicalMemoryLimitPercentage = ConfigUtil.GetIntValue(config, ConfigUtil.PhysicalMemoryLimitPercentage, _configPhysicalMemoryLimitPercentage, true, 100);
}
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && _configPhysicalMemoryLimitPercentage > 0)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_PhysicalMemoryLimitPercentage);
}
}
private void InitDisposableMembers()

View File

@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Specialized;
using System.Security;
using System.Runtime.InteropServices;
namespace System.Runtime.Caching
{
internal abstract partial class MemoryMonitor
{
static MemoryMonitor()
{
Interop.Kernel32.MEMORYSTATUSEX memoryStatusEx = default;
memoryStatusEx.dwLength = (uint)Marshal.SizeOf<Interop.Kernel32.MEMORYSTATUSEX>();
if (Interop.Kernel32.GlobalMemoryStatusEx(out memoryStatusEx) != 0)
{
s_totalPhysical = (long)memoryStatusEx.ullTotalPhys;
s_totalVirtual = (long)memoryStatusEx.ullTotalVirtual;
}
}
}
}

View File

@@ -16,7 +16,7 @@ namespace System.Runtime.Caching
// drop cache entries to avoid paging. The second monitors the amount of memory used by
// the cache itself, and helps determine when we should drop cache entries to avoid
// exceeding the cache's memory limit. Both are configurable (see ConfigUtil.cs).
internal abstract class MemoryMonitor
internal abstract partial class MemoryMonitor
{
protected const int TERABYTE_SHIFT = 40;
protected const long TERABYTE = 1L << TERABYTE_SHIFT;
@@ -39,22 +39,11 @@ namespace System.Runtime.Caching
protected int[] _pressureHist;
protected int _pressureTotal;
private static long s_totalPhysical;
private static long s_totalVirtual;
private static long s_totalPhysical = 0;
private static long s_totalVirtual = 0;
static MemoryMonitor()
{
Interop.Kernel32.MEMORYSTATUSEX memoryStatusEx;
memoryStatusEx.dwLength = (uint)Marshal.SizeOf(typeof(Interop.Kernel32.MEMORYSTATUSEX));
if (Interop.Kernel32.GlobalMemoryStatusEx(out memoryStatusEx) != 0)
{
s_totalPhysical = (long)memoryStatusEx.ullTotalPhys;
s_totalVirtual = (long)memoryStatusEx.ullTotalVirtual;
}
}
internal static long TotalPhysical { get { return s_totalPhysical; } }
internal static long TotalVirtual { get { return s_totalVirtual; } }
internal static long TotalPhysical => s_totalPhysical;
internal static long TotalVirtual => s_totalVirtual;
internal int PressureLast { get { return _pressureHist[_i0]; } }
internal int PressureHigh { get { return _pressureHigh; } }

View File

@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
namespace System.Runtime.Caching
{
internal sealed partial class PhysicalMemoryMonitor : MemoryMonitor
{
protected override int GetCurrentPressure()
{
return 0;
}
}
}

View File

@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.Caching.Configuration;
using System.Runtime.InteropServices;
using System.Security;
namespace System.Runtime.Caching
{
internal sealed partial class PhysicalMemoryMonitor : MemoryMonitor
{
protected override int GetCurrentPressure()
{
Interop.Kernel32.MEMORYSTATUSEX memoryStatusEx = default;
memoryStatusEx.dwLength = (uint)Marshal.SizeOf<Interop.Kernel32.MEMORYSTATUSEX>();
if (Interop.Kernel32.GlobalMemoryStatusEx(out memoryStatusEx) == 0)
{
return 0;
}
int memoryLoad = (int)memoryStatusEx.dwMemoryLoad;
return memoryLoad;
}
}
}

View File

@@ -12,7 +12,7 @@ namespace System.Runtime.Caching
// PhysicalMemoryMonitor monitors the amound of physical memory used on the machine
// and helps us determine when to drop entries to avoid paging and GC thrashing.
// The limit is configurable (see ConfigUtil.cs).
internal sealed class PhysicalMemoryMonitor : MemoryMonitor
internal sealed partial class PhysicalMemoryMonitor : MemoryMonitor
{
private const int MIN_TOTAL_MEMORY_TRIM_PERCENT = 10;
private static readonly long s_TARGET_TOTAL_MEMORY_TRIM_INTERVAL_TICKS = 5 * TimeSpan.TicksPerMinute;
@@ -48,7 +48,6 @@ namespace System.Runtime.Caching
*/
long memory = TotalPhysical;
Dbg.Assert(memory != 0, "memory != 0");
if (memory >= 0x100000000)
{
_pressureHigh = 99;
@@ -76,19 +75,6 @@ namespace System.Runtime.Caching
InitHistory();
}
protected override int GetCurrentPressure()
{
Interop.Kernel32.MEMORYSTATUSEX memoryStatusEx = default;
memoryStatusEx.dwLength = (uint)Marshal.SizeOf(typeof(Interop.Kernel32.MEMORYSTATUSEX));
if (Interop.Kernel32.GlobalMemoryStatusEx(out memoryStatusEx) == 0)
{
return 0;
}
int memoryLoad = (int)memoryStatusEx.dwMemoryLoad;
return memoryLoad;
}
internal override int GetPercentToTrim(DateTime lastTrimTime, int lastTrimPercent)
{
int percent = 0;

View File

@@ -33,6 +33,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Runtime.Caching;
using System.Threading;
using System.Threading.Tasks;
@@ -143,6 +144,18 @@ namespace MonoTests.System.Runtime.Caching
mc = new MemoryCache("MyCache", config);
}
[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)] // Negative case for "physicalMemoryLimitPercentage" on non Windows
public void PhysicalMemoryLimitNotSupported()
{
var config = new NameValueCollection();
config.Add("PhysicalMemoryLimitPercentage", "99");
Assert.Throws<PlatformNotSupportedException>(() =>
{
new MemoryCache("MyCache", config);
});
}
[Fact]
public void Defaults()
{
@@ -176,6 +189,7 @@ namespace MonoTests.System.Runtime.Caching
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)] // Uses "physicalMemoryLimitPercentage" not supported on other platforms
public void ConstructorValues()
{
var config = new NameValueCollection();
@@ -991,6 +1005,7 @@ namespace MonoTests.System.Runtime.Caching
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)] // Uses "physicalMemoryLimitPercentage" not supported on other platforms
public void TestExpiredGetValues()
{
var config = new NameValueCollection();
@@ -1024,6 +1039,8 @@ namespace MonoTests.System.Runtime.Caching
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)] // Uses "physicalMemoryLimitPercentage" not supported on other platforms
[OuterLoop] // makes long wait
public void TestCacheSliding()
{
var config = new NameValueCollection();
@@ -1039,7 +1056,8 @@ namespace MonoTests.System.Runtime.Caching
// The sliding expiration timeout has to be greater than 1 second because
// .NET implementation ignores timeouts updates smaller than
// CacheExpires.MIN_UPDATE_DELTA which is equal to 1.
cip.SlidingExpiration = TimeSpan.FromSeconds(2);
const int SlidingExpirationThresholdMSec = 4000;
cip.SlidingExpiration = TimeSpan.FromMilliseconds(SlidingExpirationThresholdMSec);
mc.Add("slidingtest", "42", cip);
mc.Add("expire1", "1", cip);
@@ -1049,13 +1067,28 @@ namespace MonoTests.System.Runtime.Caching
mc.Add("expire5", "5", cip);
Assert.Equal(6, mc.GetCount());
// The loop below would sleep for ~5 seconds total (in 50 intervals).
// Each of these intervals is only supposed to be ~100ms.
// However due to concurrency with other tests and various system conditions,
// we observe occasional delays that are much longer than the SlidingExpirationThresholdMSec
// expiration period which causes the "slidingtest" cache item to expire
Stopwatch sw = new Stopwatch();
for (int i = 0; i < 50; i++)
{
sw.Restart();
Thread.Sleep(100);
var item = mc.Get("slidingtest");
Assert.NotEqual(null, item);
sw.Stop();
if (sw.ElapsedMilliseconds < SlidingExpirationThresholdMSec)
{
Assert.NotEqual(null, item);
}
else
{
// for the sake of simplicity skip an inversed assert here (Assert.Equal(null, item))
// (to avoid further complicating the test as we would need to address a few more subtle timing cases)
}
}
Assert.Null(mc.Get("expire1"));
@@ -1065,7 +1098,7 @@ namespace MonoTests.System.Runtime.Caching
Assert.Null(mc.Get("expire5"));
Assert.Equal(1, mc.GetCount());
Thread.Sleep(3000);
Thread.Sleep(SlidingExpirationThresholdMSec + 1000);
Assert.Null(mc.Get("slidingtest"));
Assert.Equal(0, mc.GetCount());
@@ -1314,6 +1347,7 @@ namespace MonoTests.System.Runtime.Caching
public class MemoryCacheTestExpires4
{
[Fact]
[PlatformSpecific(TestPlatforms.Windows)] // Uses "physicalMemoryLimitPercentage" not supported on other platforms
public async Task TestCacheShrink()
{
const int HEAP_RESIZE_THRESHOLD = 8192 + 2;
@@ -1371,6 +1405,7 @@ namespace MonoTests.System.Runtime.Caching
public class MemoryCacheTestExpires5
{
[Fact]
[PlatformSpecific(TestPlatforms.Windows)] // Uses "physicalMemoryLimitPercentage" not supported on other platforms
public async Task TestCacheExpiryOrdering()
{
var config = new NameValueCollection();