1 //
2 // Copyright © 2019 Jamie Madill
3 //
4 // This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
5 //
6 // glmark2 is free software: you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the Free Software
8 // Foundation, either version 3 of the License, or (at your option) any later
9 // version.
10 //
11 // glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU General Public License along with
17 // glmark2.  If not, see <http://www.gnu.org/licenses/>.
18 //
19 // Authors:
20 //  Jamie Madill
21 //
22 // From Stack Overflow under Create Commons license:
23 // https://stackoverflow.com/a/31335254
24 
25 #ifndef SYS_TIME_H_FOR_WINDOWS_
26 #define SYS_TIME_H_FOR_WINDOWS_
27 
28 #ifdef _WIN32
29 #include <time.h>
30 #include <windows.h>
31 #define CLOCK_MONOTONIC 0
clock_gettime(int,struct timespec * spec)32 inline int clock_gettime(int, struct timespec *spec)
33 {
34     __int64 wintime;
35     GetSystemTimeAsFileTime((FILETIME*)&wintime);
36     wintime      -= 116444736000000000i64;           // 1601 to 1970
37     spec->tv_sec  = wintime / 10000000i64;           // seconds
38     spec->tv_nsec = wintime % 10000000i64 *100;      // nanoseconds
39     return 0;
40 }
41 #else
42 #include <sys/time.h>
43 #endif
44 
45 #endif  // SYS_TIME_H_FOR_WINDOWS_
46