Skip to content

Commit d443e55

Browse files
committed
IOCP.FFI: make queryPerformanceCounter throw an exception on failure
QueryPerformanceCounter is not expected to fail after QueryPerformanceFrequency succeeded.
1 parent 9e495b5 commit d443e55

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

IOCP/FFI.hsc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,20 @@ callQP qpfunc =
222222
--
223223
-- Problems:
224224
--
225+
-- * Might not be available on some hardware. Use 'queryPerformanceFrequency'
226+
-- to test for availability before calling this function.
227+
--
225228
-- * On a multiprocessor computer, may produce different results on
226229
-- different processors due to hardware bugs.
227230
--
228231
-- To get a monotonic time in seconds, divide the result of
229232
-- 'queryPerformanceCounter' by that of 'queryPerformanceFrequency'.
230233
--
231234
-- <http://msdn.microsoft.com/en-us/library/windows/desktop/ms644904%28v=vs.85%29.aspx>
232-
queryPerformanceCounter :: IO (Maybe Int64)
233-
queryPerformanceCounter = callQP c_QueryPerformanceCounter
235+
queryPerformanceCounter :: IO Int64
236+
queryPerformanceCounter =
237+
callQP c_QueryPerformanceCounter
238+
>>= maybe (Win32.errorWin "QueryPerformanceCounter") return
234239

235240
-- | Call the @QueryPerformanceFrequency@ function. Return 'Nothing' if the
236241
-- hardware does not provide a high-resolution performance counter.

testing/monotonic-time.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ main = do
2929
t64 <- maybe (return Nothing) (fmap Just) gtc64
3030
qpc <- case freq of
3131
Nothing -> return Nothing
32-
Just f -> fmap (\c -> (c, f)) <$> queryPerformanceCounter
32+
Just f -> (\c -> Just (c, f)) <$> queryPerformanceCounter
3333
putStrLn $ formatTimes t t64 qpc
3434

3535
formatTimes t t64 qpc =

0 commit comments

Comments
 (0)