root/opal/win32/opal_time.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. gettimeofday

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2014 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * $COPYRIGHT$
  13  *
  14  * Additional copyrights may follow
  15  *
  16  * $HEADER$
  17  */
  18 
  19 #include "opal_config.h"
  20 #include "opal/win32/opal_time.h"
  21 
  22 #include<time.h>
  23 
  24 #define EPOCHFILETIME (116444736000000000LL)
  25 
  26 int gettimeofday(struct timeval *tv, struct timezone *tz)
  27 {
  28     FILETIME file_time;
  29     LARGE_INTEGER place_holder;
  30     __int64 time;
  31 
  32 
  33     /* returns 64 bit value which is the number of 100 nanosecond
  34        intervals since 1601(UTC) */
  35     GetSystemTimeAsFileTime (&file_time);
  36 
  37     /* Windows recommends that we should copy the FILETIME returned
  38        into a ULARGE_INTEGER and then perform the arithmetic on that */
  39     place_holder.LowPart = file_time.dwLowDateTime;
  40     place_holder.HighPart = file_time.dwHighDateTime;
  41     time = place_holder.QuadPart;
  42     time -= EPOCHFILETIME;
  43 
  44     /* Now we can use arithmetic operations on time which is nothing but
  45        a 64 bit integer holding time in 100 nanosec intervals */
  46 
  47     /* convert 100 nanoseconds intervals into microseconds .. divide by 10 */
  48     time /= 10;
  49 
  50     tv->tv_sec = (long)(time / 1000000);
  51     tv->tv_usec = (long)(time % 1000000);
  52 
  53     return 0;
  54 }

/* [<][>][^][v][top][bottom][index][help] */