-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpdutils.c
77 lines (54 loc) · 1.19 KB
/
mpdutils.c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include "list.h"
#include <sys/time.h>
#include "mpdutils.h"
unsigned long get_uptime(void)
{
struct timespec tm;
if (clock_gettime(CLOCK_MONOTONIC, &tm) != 0)
return 0;
return tm.tv_sec;
}
uint64_t GetCurrentTick()
{
struct timespec tm;
if (clock_gettime(CLOCK_MONOTONIC, &tm) != 0)
return 0;
return ((uint64_t)tm.tv_sec) * 1000 + tm.tv_nsec / 1000000;
}
void Sleep(unsigned int milliseconds)
{
struct timespec request;
request.tv_sec = milliseconds / 1000;
request.tv_nsec = (milliseconds % 1000) * 1000000;
nanosleep(&request, NULL);
}
unsigned long long monotonic_ns(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000000ULL + tv.tv_usec * 1000;
}
unsigned long long monotonic_us(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000ULL + tv.tv_usec;
}
unsigned long long monotonic_ms(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000ULL + tv.tv_usec / 1000;
}
unsigned monotonic_sec(void)
{
return time(NULL);
}