Move QueryPerformanceCounter PInvokes to shared (dotnet/corefx#36409)
authorJan Kotas <jkotas@microsoft.com>
Thu, 28 Mar 2019 05:37:22 +0000 (22:37 -0700)
committerJan Kotas <jkotas@microsoft.com>
Thu, 28 Mar 2019 06:19:18 +0000 (23:19 -0700)
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceCounter.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceFrequency.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems

diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceCounter.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceCounter.cs
new file mode 100644 (file)
index 0000000..ddc9797
--- /dev/null
@@ -0,0 +1,22 @@
+// 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.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Kernel32
+    {
+        // The actual native signature is:
+        //      BOOL WINAPI QueryPerformanceCounter(
+        //          _Out_ LARGE_INTEGER* lpPerformanceCount
+        //      );
+        //
+        // We take a long* (rather than a out long) to avoid the pinning overhead.
+        // We don't set last error since we don't need the extended error info.
+
+        [DllImport(Libraries.Kernel32, ExactSpelling = true)]
+        internal static extern unsafe BOOL QueryPerformanceCounter(long* lpPerformanceCount);
+    }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceFrequency.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceFrequency.cs
new file mode 100644 (file)
index 0000000..72a48ba
--- /dev/null
@@ -0,0 +1,22 @@
+// 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.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Kernel32
+    {
+        // The actual native signature is:
+        //      BOOL WINAPI QueryPerformanceFrequency(
+        //          _Out_ LARGE_INTEGER* lpFrequency
+        //      );
+        //
+        // We take a long* (rather than a out long) to avoid the pinning overhead.
+        // We don't set last error since we don't need the extended error info.
+
+        [DllImport(Libraries.Kernel32, ExactSpelling = true)]
+        internal static extern unsafe BOOL QueryPerformanceFrequency(long* lpFrequency);
+    }
+}
index 3cd36e0..3b56c77 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.MEMORYSTATUSEX.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.MultiByteToWideChar.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.OutputDebugString.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.QueryPerformanceCounter.cs" Condition="'$(FeaturePortableThreadPool)' == 'true'" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.QueryPerformanceFrequency.cs" Condition="'$(FeaturePortableThreadPool)' == 'true'" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.ReadFile_SafeHandle_IntPtr.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.ReadFile_SafeHandle_NativeOverlapped.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.ResolveLocaleName.cs" />