-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimes.h
More file actions
36 lines (27 loc) · 735 Bytes
/
times.h
File metadata and controls
36 lines (27 loc) · 735 Bytes
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
/* SPDX-License-Identifier: MIT */
/*
* Copyright (c) 2021, Linus Lüssing
*/
#ifndef __TIMES_H__
#define __TIMES_H__
static inline struct timespec timespec_sum(const struct timespec aug,
const struct timespec add)
{
struct timespec res = aug;
res.tv_sec += add.tv_sec;
res.tv_nsec += add.tv_nsec;
if (res.tv_nsec >= 1000000000L) {
res.tv_sec++;
res.tv_nsec -= 1000000000L;
}
return res;
}
static inline int64_t timespec_diffus(const struct timespec before,
const struct timespec after)
{
int64_t diff_us = (int64_t)after.tv_sec - (int64_t)before.tv_sec;
diff_us *= 1000 * 1000;
diff_us += ((int64_t)after.tv_nsec - (int64_t)before.tv_nsec) / 1000;
return diff_us;
}
#endif /* __TIMES_H__ */