Remove unnecessary error check for QueryUnbiasedInterruptTime call (dotnet/coreclr...
authorAaron Robinson <arobins@microsoft.com>
Mon, 12 Aug 2019 06:08:03 +0000 (23:08 -0700)
committerGitHub <noreply@github.com>
Mon, 12 Aug 2019 06:08:03 +0000 (23:08 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/8739b11ca4ec6ed3c5bec854d864b2252ab14861

src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.QueryUnbiasedInterruptTime.cs
src/libraries/System.Private.CoreLib/src/System/Threading/TimerQueue.Windows.cs

index 87ca7fd..db225ff 100644 (file)
@@ -8,7 +8,7 @@ internal partial class Interop
 {
     internal partial class Kernel32
     {
-        [DllImport(Libraries.Kernel32, SetLastError = true)]
+        [DllImport(Libraries.Kernel32)]
         internal static extern bool QueryUnbiasedInterruptTime(out ulong UnbiasedTime);
     }
 }
index 38a14a1..bd55e43 100644 (file)
@@ -2,6 +2,7 @@
 // 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.Diagnostics;
 using System.Runtime.InteropServices;
 
 namespace System.Threading
@@ -21,9 +22,11 @@ namespace System.Threading
                 // in sleep/hibernate mode.
                 if (Environment.IsWindows8OrAbove)
                 {
-                    if (!Interop.Kernel32.QueryUnbiasedInterruptTime(out ulong time100ns))
-                        Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
-
+                    // Based on its documentation the QueryUnbiasedInterruptTime() function validates
+                    // the argument is non-null. In this case we are always supplying an argument,
+                    // so will skip return value validation.
+                    bool success = Interop.Kernel32.QueryUnbiasedInterruptTime(out ulong time100ns);
+                    Debug.Assert(success);
                     return (long)(time100ns / 10_000); // convert from 100ns to milliseconds
                 }
                 else