-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos_linux.cpp
47 lines (38 loc) · 840 Bytes
/
os_linux.cpp
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
#include <unistd.h>
#include <cstdint>
#include <sys/time.h>
#include <time.h>
#if _POSIX_C_SOURCE >= 199309L
#include <time.h> // for nanosleep
#else
#include <unistd.h> // for usleep
#endif
namespace OS {
extern void DelayUS(uint32_t US)
{
#if _POSIX_C_SOURCE >= 199309L
struct timespec ts;
const uint32_t MS = US / 1000UL;
ts.tv_sec = MS / 1000UL;
ts.tv_nsec = (MS % 1000UL) * 1000000UL;
nanosleep(&ts, NULL);
#else
usleep(US);
#endif
}
extern void DelayMS(uint32_t MS)
{
DelayUS(MS * 1000);
}
extern void DelaySeconds(uint32_t Seconds)
{
sleep(Seconds);
}
extern uint32_t GetFreeRunningUS(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
const uint64_t US = tv.tv_sec * 1000000ULL + tv.tv_usec;
return (uint32_t) US;
}
}