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> | |
22 | #include <time.h> | |
23 | ||
24 | inline int64_t GetTimeMs() | |
25 | { | |
26 | #ifdef __WINDOWS__ | |
27 | time_t rawtime; | |
28 | time(&rawtime); | |
29 | ||
30 | LARGE_INTEGER tickPerSecond; | |
31 | LARGE_INTEGER tick; | |
32 | if (QueryPerformanceFrequency(&tickPerSecond)) | |
33 | { | |
34 | QueryPerformanceCounter(&tick); | |
35 | return (int64_t) (tick.QuadPart / 1000.); | |
36 | } | |
37 | return -1; | |
38 | #else | |
39 | struct timespec time; | |
40 | clock_gettime(CLOCK_MONOTONIC, &time); | |
41 | ||
42 | return ((int64_t)time.tv_sec * (int64_t)1000) + (int64_t)time.tv_nsec / (int64_t)1000; | |
43 | #endif | |
44 | } | |
45 | ||
46 | template <class T> | |
47 | inline T GetTimeSec() | |
48 | { | |
49 | return (T)GetTimeMs() / (T)1000.0; | |
50 | } | |
51 | ||
52 | void USleep(int64_t usecs, volatile bool* stop = NULL); |