Added README file
[swift-upb.git] / compat / hirestimeofday.h
1 /*
2  * Written by Arno Bakker
3  * see LICENSE.txt for license information
4  *
5  * Singleton class to retrieve a time-of-day in UTC in usec in a platform-
6  * independent manner.
7  */
8 #ifndef HIRESTIMEOFDAY_H
9 #define HIRESTIMEOFDAY_H
10
11 #ifdef _MSC_VER
12 #include "compat/stdint.h"
13 #else
14 #include <stdint.h>
15 #endif
16 #ifdef _WIN32
17 #include <windows.h>
18 #endif
19
20 namespace swift {
21
22 typedef int64_t tint;
23 #define TINT_SEC ((tint)1000000)
24 #define TINT_MSEC ((tint)1000)
25 #define TINT_uSEC ((tint)1)
26 #define TINT_NEVER ((tint)0x7fffffffffffffffLL)
27
28
29 class HiResTimeOfDay
30 {
31 public:
32     HiResTimeOfDay(void);
33     tint getTimeUSec(void);
34     static HiResTimeOfDay* Instance();
35
36 private:
37 #ifdef _WIN32
38         tint     epochstart; // in usec
39         LARGE_INTEGER epochcounter;
40     LARGE_INTEGER last;
41     LARGE_INTEGER frequency;
42
43     tint HiResTimeOfDay::getFTime();
44     LARGE_INTEGER getFrequency(void);
45     LARGE_INTEGER getCounter(void);
46 #endif
47
48     static HiResTimeOfDay* _instance;
49 };
50
51 };
52 #endif