[Lemon-commits] [lemon_svn] deba: r2666 - hugo/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:54:19 CET 2006


Author: deba
Date: Fri Mar 31 14:12:06 2006
New Revision: 2666

Modified:
   hugo/trunk/lemon/time_measure.h

Log:
MinGW compatibility fix




Modified: hugo/trunk/lemon/time_measure.h
==============================================================================
--- hugo/trunk/lemon/time_measure.h	(original)
+++ hugo/trunk/lemon/time_measure.h	Fri Mar 31 14:12:06 2006
@@ -23,8 +23,80 @@
 ///\file
 ///\brief Tools for measuring cpu usage
 
-#include <sys/time.h>
+
+#ifdef WIN32
+
+#include <windows.h>
+#include <time.h>
+#include "dos.h"
+
+int gettimeofday(struct timeval * tp, struct timezone *) {
+  SYSTEMTIME      systime;
+
+  if (tp) {
+
+    struct tm tmrec;
+    time_t theTime = time(NULL);
+
+    tmrec = *localtime(&theTime);
+    tp->tv_sec = mktime(&tmrec);
+    GetLocalTime(&systime); /* system time */
+
+    tp->tv_usec = systime.wMilliseconds * 1000;
+
+  }
+
+  return 0;
+
+}
+
+struct tms {
+  long	tms_utime;
+  long	tms_stime;
+  long	tms_cutime;
+  long	tms_cstime;
+};
+
+static long filetime_to_clock(FILETIME *ft)
+{
+  __int64 qw = ft->dwHighDateTime;
+  qw <<= 32;
+  qw |= ft->dwLowDateTime;
+  qw /= 10000;  /* File time ticks at 0.1uS, clock at 1mS */
+  return (long) qw;
+
+}
+
+int times(struct tms *tmbuf)
+{
+  FILETIME create, exit, kernel, user;
+  if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
+    tmbuf->tms_utime = filetime_to_clock(&user);
+    tmbuf->tms_stime = filetime_to_clock(&kernel);
+    tmbuf->tms_cutime = 0;
+    tmbuf->tms_cstime = 0;
+  }
+  else {
+    tmbuf->tms_utime = clock();
+    tmbuf->tms_stime = 0;
+    tmbuf->tms_cutime = 0;
+    tmbuf->tms_cstime = 0;
+  }
+  return 0;
+}
+
+#define _SC_CLK_TCK 1
+
+int sysconf(int)
+{
+  return 1;
+}
+
+#else
 #include <sys/times.h>
+#endif
+
+#include <sys/time.h>
 #include <fstream>
 #include <iostream>
 #include <unistd.h>
@@ -510,7 +582,7 @@
   
   template<class F>
   TimeStamp runningTimeTest(F f,double min_time=10,int *num = NULL,
-			TimeStamp *full_time=NULL)
+                            TimeStamp *full_time=NULL)
   {
     Timer t;
     TimeStamp full;



More information about the Lemon-commits mailing list