The Windows counterpart to 'wrapround of thread delays'
authorIan Lynagh <igloo@earth.li>
Fri, 9 Feb 2007 17:35:10 +0000 (17:35 +0000)
committerIan Lynagh <igloo@earth.li>
Fri, 9 Feb 2007 17:35:10 +0000 (17:35 +0000)
GHC/Conc.lhs
cbits/Win32Utils.c
include/HsBase.h

index bd03295..e37619a 100644 (file)
@@ -98,7 +98,7 @@ import Data.Maybe
 import GHC.Base
 import GHC.IOBase
 import GHC.Num         ( Num(..) )
-import GHC.Real                ( fromIntegral, quot )
+import GHC.Real                ( fromIntegral, div )
 #ifndef mingw32_HOST_OS
 import GHC.Base                ( Int(..) )
 #endif
@@ -707,8 +707,8 @@ data IOReq
 #endif
 
 data DelayReq
-  = Delay    {-# UNPACK #-} !Word64 {-# UNPACK #-} !(MVar ())
-  | DelaySTM {-# UNPACK #-} !Word64 {-# UNPACK #-} !(TVar Bool)
+  = Delay    {-# UNPACK #-} !USecs {-# UNPACK #-} !(MVar ())
+  | DelaySTM {-# UNPACK #-} !USecs {-# UNPACK #-} !(TVar Bool)
 
 #ifndef mingw32_HOST_OS
 pendingEvents :: IORef [IOReq]
@@ -736,6 +736,7 @@ insertDelay d1 ds@(d2 : rest)
   | delayTime d1 <= delayTime d2 = d1 : ds
   | otherwise                    = d2 : insertDelay d1 rest
 
+delayTime :: DelayReq -> USecs
 delayTime (Delay t _) = t
 delayTime (DelaySTM t _) = t
 
@@ -836,9 +837,10 @@ getDelay now all@(d : rest)
        atomically $ writeTVar t True
        getDelay now rest
      _otherwise ->
-        return (all, (fromIntegral (delayTime d - now) * 
-                        fromIntegral tick_msecs))
-                        -- delay is in millisecs for WaitForSingleObject
+        -- delay is in millisecs for WaitForSingleObject
+        let micro_seconds = delayTime d - now
+            milli_seconds = (micro_seconds + 999) `div` 1000
+        in return (all, fromIntegral milli_seconds)
 
 -- ToDo: this just duplicates part of System.Win32.Types, which isn't
 -- available yet.  We should move some Win32 functionality down here,
index 942b2c4..0f4eb52 100644 (file)
@@ -107,18 +107,16 @@ void maperrno (void)
                        errno = EINVAL;
 }
 
-#define TICKS_PER_SECOND 50
-// must match GHC.Conc.tick_freq
-
-HsInt getTicksOfDay(void)
+HsWord64 getUSecOfDay(void)
 {
-    HsInt64 t;
+    HsWord64 t;
     FILETIME ft;
     GetSystemTimeAsFileTime(&ft);
-    t = ((HsInt64)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
-    t = (t * TICKS_PER_SECOND) / 10000000LL;
-      /* FILETIMES are in units of 100ns */
-    return (HsInt)t;
+    t = ((HsWord64)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
+    t = t / 10LL;
+    /* FILETIMES are in units of 100ns,
+       so we divide by 10 to get microseconds */
+    return t;
 }
 
 #endif
index 519adf7..09693cb 100644 (file)
 #if defined(__MINGW32__)
 /* in Win32Utils.c */
 extern void maperrno (void);
-extern HsInt getUSecOfDay(void);
+extern HsWord64 getUSecOfDay(void);
 #endif
 
 #if defined(__MINGW32__)