[project @ 1999-05-03 13:22:29 by sof]
[ghc-hetmet.git] / ghc / lib / std / cbits / getClockTime.c
index 07e032b..9b96e33 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
  *
- * $Id: getClockTime.c,v 1.3 1998/12/02 13:27:38 simonm Exp $
+ * $Id: getClockTime.c,v 1.4 1999/05/03 13:22:29 sof Exp $
  *
  * getClockTime Runtime Support
  */
 # endif
 #endif
 
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#include <sys/types.h>
+#include <sys/timeb.h>
+#endif
+
 StgInt
 getClockTime(StgByteArray sec, StgByteArray nsec)
 {
-#ifdef HAVE_GETCLOCK
+#if defined(_WIN32)
+  struct timeb t;
+
+  _ftime(&t);
+
+  ((unsigned int *)sec)[0] = (unsigned int)t.time;
+  ((unsigned int *)nsec)[0] = (unsigned int)t.millitm * 1000;
+  return 0;
+#elif defined(HAVE_GETCLOCK)
     struct timespec tp;
 
     if (getclock(TIMEOFDAY, &tp) != 0) {
@@ -50,8 +64,7 @@ getClockTime(StgByteArray sec, StgByteArray nsec)
     ((unsigned long int *)sec)[0] = tp.tv_sec;
     ((unsigned long int *)nsec)[0] = tp.tv_nsec;
     return 0;
-#else
-#ifdef HAVE_GETTIMEOFDAY
+#elif defined(HAVE_GETTIMEOFDAY)
     struct timeval tp;
  
     if (gettimeofday(&tp, NULL) != 0) {
@@ -73,13 +86,20 @@ getClockTime(StgByteArray sec, StgByteArray nsec)
     ((unsigned long int *)nsec)[0] = 0;
     return 0;
 #endif
-#endif
 }
 
 StgInt
 prim_getClockTime(StgByteArray sec, StgByteArray nsec)
 {
-#ifdef HAVE_GETCLOCK
+#if defined(_WIN32)
+  struct timeb t;
+
+  _ftime(&t);
+
+  ((unsigned long int *)sec)[0] = t.time;
+  ((unsigned long int *)nsec)[0] = t.millitm * 1000;
+  return 0;
+#elif defined(HAVE_GETCLOCK)
     struct timespec tp;
 
     if (getclock(TIMEOFDAY, &tp) != 0) {
@@ -90,8 +110,7 @@ prim_getClockTime(StgByteArray sec, StgByteArray nsec)
     ((StgInt64*)sec)[0] = tp.tv_sec;
     ((StgInt64*)nsec)[0] = tp.tv_nsec;
     return 0;
-#else
-#ifdef HAVE_GETTIMEOFDAY
+#elif defined(HAVE_GETTIMEOFDAY)
     struct timeval tp;
  
     if (gettimeofday(&tp, NULL) != 0) {
@@ -113,5 +132,4 @@ prim_getClockTime(StgByteArray sec, StgByteArray nsec)
     ((StgInt64*)nsec)[0] = 0;
     return 0;
 #endif
-#endif
 }