[MLton] fixedGetrusage proposal for MinGW mlton

Bernard Berthomieu Bernard.Berthomieu at laas.fr
Wed Sep 6 08:15:44 PDT 2006


I just saw on http://mlton.org/RunningOnMinGW:

    *

      The C function getrusage is implemented by a stub that always sets
      the time to zero.
      Hence MLton.Rusage.rusage will return times of zero. Also, the
      times printed by the
      runtime system will be zeroes

Here is the version of fixedGetrusage (in runtime/platform/mingw.c) we 
are using
in our Linux to MinGW cross-compiling mlton.


/* GetProcessTimes and GetSystemTimeAsFileTime are documented at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getprocesstimes.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemtimeasfiletime.asp
*/
int fixedGetrusage (int who, struct rusage *usage) {
  FILETIME ct, et, kt, ut;
  LARGE_INTEGER li, lj;
  if (GetProcessTimes(GetCurrentProcess(), &ct, &et, &kt, &ut)) {
    usage->ru_utime.tv_sec = ut.dwHighDateTime;
    usage->ru_utime.tv_usec = ut.dwLowDateTime/10;
    usage->ru_stime.tv_sec = kt.dwHighDateTime;
    usage->ru_stime.tv_usec = kt.dwLowDateTime/10;
    return 0;
  }
  /* if GetProcessTimes failed, use real time [for Windows] */
  GetSystemTimeAsFileTime(&ut);
  li.LowPart = ut.dwLowDateTime;
  li.HighPart = ut.dwHighDateTime;
  lj.LowPart = Time_sec;
  lj.HighPart = Time_usec;
  li.QuadPart -= lj.QuadPart;
  usage->ru_utime.tv_sec = li.HighPart;
  usage->ru_utime.tv_usec = li.LowPart/10;
  usage->ru_stime.tv_sec = 0;
  usage->ru_stime.tv_usec = 0;
  return 0;
}


  Bernard.




More information about the MLton mailing list