Commit | Line | Data |
---|---|---|
abbca718 LOK |
1 | #pragma once |
2 | ||
3 | /* | |
4 | * boblight | |
5 | * Copyright (C) Bob 2009 | |
6 | * | |
7 | * boblight is free software: you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation, either version 3 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * boblight is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
15 | * See the GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License along | |
18 | * with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
21 | #include <stdint.h> | |
40339852 | 22 | #include <sys/time.h> |
6df2c52f | 23 | #if defined(__APPLE__) |
24 | #include <mach/mach_time.h> | |
25 | #include <CoreVideo/CVHostTime.h> | |
26 | #endif | |
abbca718 | 27 | |
b9187cc6 | 28 | namespace CEC |
abbca718 | 29 | { |
b9187cc6 | 30 | inline int64_t GetTimeMs() |
abbca718 | 31 | { |
6df2c52f | 32 | #if defined(__APPLE__) |
33 | return (int64_t) (CVGetCurrentHostTime() * 1000 / CVGetHostClockFrequency()); | |
34 | #elif defined(__WINDOWS__) | |
b9187cc6 LOK |
35 | time_t rawtime; |
36 | time(&rawtime); | |
abbca718 | 37 | |
b9187cc6 LOK |
38 | LARGE_INTEGER tickPerSecond; |
39 | LARGE_INTEGER tick; | |
40 | if (QueryPerformanceFrequency(&tickPerSecond)) | |
41 | { | |
42 | QueryPerformanceCounter(&tick); | |
43 | return (int64_t) (tick.QuadPart / 1000.); | |
44 | } | |
45 | return -1; | |
46 | #else | |
40339852 LOK |
47 | timeval time; |
48 | gettimeofday(&time, NULL); | |
49 | return (int64_t) (time.tv_sec * 1000 + time.tv_usec / 1000); | |
b9187cc6 LOK |
50 | #endif |
51 | } | |
abbca718 | 52 | |
b9187cc6 LOK |
53 | template <class T> |
54 | inline T GetTimeSec() | |
55 | { | |
56 | return (T)GetTimeMs() / (T)1000.0; | |
57 | } | |
58 | }; |