blob: c77b8db6858baf7afd43759f16ea35d98500329a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
//
// Copyright 2017 Garrett D'Amore <garrett@damore.org>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt). A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//
#ifndef STUBS_H
#define STUBS_H
#include <stdint.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <time.h>
#include <sys/time.h>
#endif
// Stub handlers for some common things.
uint64_t
getms(void)
{
#ifdef _WIN32
return (GetTickCount64()) ;
#else
static time_t epoch;
struct timeval tv;
if (epoch == 0) {
epoch = time(NULL);
}
gettimeofday(&tv, NULL);
if (tv.tv_sec < epoch) {
// Broken clock.
// This will force all other timing tests to fail
return (0);
}
tv.tv_sec -= epoch;
return (((uint64_t)(tv.tv_sec ) * 1000) + (tv.tv_usec / 1000));
#endif
}
#endif // STUBS_H
|