hptime.c

Go to the documentation of this file.
00001 
00039 #include "hptime.h"
00040 
00041 #if defined(_WIN32)
00042 
00043 #include <windows.h>
00044 
00045 hptime_t hptime_get(void)
00046 {
00047     FILETIME ft;
00048 
00049     /*
00050      * La precisione dei FileTime sarebbe 100ns, ma il
00051      * valore viene ottenuto convertendo una struttura
00052      * SYSTEMTIME, che ha precisione di 1ms. Il numero
00053      * che otteniamo e' quindi sempre un multiplo di
00054      * 100000.
00055      */
00056     GetSystemTimeAsFileTime(&ft);
00057 
00058     /* Copy the upper/lower into a quadword. */
00059     return (((hptime_t)ft.dwHighDateTime) << 32) + (hptime_t)ft.dwLowDateTime;
00060 }
00061 
00062 #elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
00063 
00064 #include <sys/time.h> /* for gettimeofday() */
00065 #include <stddef.h> /* for NULL */
00066 
00067 hptime_t hptime_get(void)
00068 {
00069     struct timeval tv;
00070 
00071     gettimeofday(&tv, NULL);
00072     return (hptime_t)tv.tv_sec * HPTIME_TICKS_PER_SECOND
00073         + (hptime_t)tv.tv_usec;
00074 }
00075 
00076 #else /* !__unix__ */
00077     #error OS dependent support code missing for this OS
00078 #endif /* !__unix__ */
00079