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