MinGW compatibility fix
authordeba
Fri, 31 Mar 2006 12:12:06 +0000
changeset 2027119db4e6ab2c
parent 2026 8d49961ec50f
child 2028 d0e8a86a1ff2
MinGW compatibility fix
lemon/time_measure.h
     1.1 --- a/lemon/time_measure.h	Fri Mar 31 12:04:48 2006 +0000
     1.2 +++ b/lemon/time_measure.h	Fri Mar 31 12:12:06 2006 +0000
     1.3 @@ -23,8 +23,80 @@
     1.4  ///\file
     1.5  ///\brief Tools for measuring cpu usage
     1.6  
     1.7 +
     1.8 +#ifdef WIN32
     1.9 +
    1.10 +#include <windows.h>
    1.11 +#include <time.h>
    1.12 +#include "dos.h"
    1.13 +
    1.14 +int gettimeofday(struct timeval * tp, struct timezone *) {
    1.15 +  SYSTEMTIME      systime;
    1.16 +
    1.17 +  if (tp) {
    1.18 +
    1.19 +    struct tm tmrec;
    1.20 +    time_t theTime = time(NULL);
    1.21 +
    1.22 +    tmrec = *localtime(&theTime);
    1.23 +    tp->tv_sec = mktime(&tmrec);
    1.24 +    GetLocalTime(&systime); /* system time */
    1.25 +
    1.26 +    tp->tv_usec = systime.wMilliseconds * 1000;
    1.27 +
    1.28 +  }
    1.29 +
    1.30 +  return 0;
    1.31 +
    1.32 +}
    1.33 +
    1.34 +struct tms {
    1.35 +  long	tms_utime;
    1.36 +  long	tms_stime;
    1.37 +  long	tms_cutime;
    1.38 +  long	tms_cstime;
    1.39 +};
    1.40 +
    1.41 +static long filetime_to_clock(FILETIME *ft)
    1.42 +{
    1.43 +  __int64 qw = ft->dwHighDateTime;
    1.44 +  qw <<= 32;
    1.45 +  qw |= ft->dwLowDateTime;
    1.46 +  qw /= 10000;  /* File time ticks at 0.1uS, clock at 1mS */
    1.47 +  return (long) qw;
    1.48 +
    1.49 +}
    1.50 +
    1.51 +int times(struct tms *tmbuf)
    1.52 +{
    1.53 +  FILETIME create, exit, kernel, user;
    1.54 +  if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
    1.55 +    tmbuf->tms_utime = filetime_to_clock(&user);
    1.56 +    tmbuf->tms_stime = filetime_to_clock(&kernel);
    1.57 +    tmbuf->tms_cutime = 0;
    1.58 +    tmbuf->tms_cstime = 0;
    1.59 +  }
    1.60 +  else {
    1.61 +    tmbuf->tms_utime = clock();
    1.62 +    tmbuf->tms_stime = 0;
    1.63 +    tmbuf->tms_cutime = 0;
    1.64 +    tmbuf->tms_cstime = 0;
    1.65 +  }
    1.66 +  return 0;
    1.67 +}
    1.68 +
    1.69 +#define _SC_CLK_TCK 1
    1.70 +
    1.71 +int sysconf(int)
    1.72 +{
    1.73 +  return 1;
    1.74 +}
    1.75 +
    1.76 +#else
    1.77 +#include <sys/times.h>
    1.78 +#endif
    1.79 +
    1.80  #include <sys/time.h>
    1.81 -#include <sys/times.h>
    1.82  #include <fstream>
    1.83  #include <iostream>
    1.84  #include <unistd.h>
    1.85 @@ -510,7 +582,7 @@
    1.86    
    1.87    template<class F>
    1.88    TimeStamp runningTimeTest(F f,double min_time=10,int *num = NULL,
    1.89 -			TimeStamp *full_time=NULL)
    1.90 +                            TimeStamp *full_time=NULL)
    1.91    {
    1.92      Timer t;
    1.93      TimeStamp full;