Xenomai 3.3.2
Loading...
Searching...
No Matches
time.h
1/*
2 * Copyright (C) 2013 Philippe Gerum <rpm@xenomai.org>.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 */
18#ifndef _BOILERPLATE_TIME_H
19#define _BOILERPLATE_TIME_H
20
21#include <time.h>
22
23typedef unsigned long long ticks_t;
24
25typedef long long sticks_t;
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31void timespec_sub(struct timespec *__restrict r,
32 const struct timespec *__restrict t1,
33 const struct timespec *__restrict t2);
34
35void timespec_subs(struct timespec *__restrict r,
36 const struct timespec *__restrict t1,
37 sticks_t t2);
38
39void timespec_add(struct timespec *__restrict r,
40 const struct timespec *__restrict t1,
41 const struct timespec *__restrict t2);
42
43void timespec_adds(struct timespec *__restrict r,
44 const struct timespec *__restrict t1,
45 sticks_t t2);
46
47void timespec_sets(struct timespec *__restrict r,
48 ticks_t ns);
49
50#ifdef __cplusplus
51}
52#endif
53
54static inline sticks_t timespec_scalar(const struct timespec *__restrict t)
55{
56 return t->tv_sec * 1000000000LL + t->tv_nsec;
57}
58
59static inline int __attribute__ ((always_inline))
60timespec_before(const struct timespec *__restrict t1,
61 const struct timespec *__restrict t2)
62{
63 if (t1->tv_sec < t2->tv_sec)
64 return 1;
65
66 if (t1->tv_sec == t2->tv_sec &&
67 t1->tv_nsec < t2->tv_nsec)
68 return 1;
69
70 return 0;
71}
72
73static inline int __attribute__ ((always_inline))
74timespec_before_or_same(const struct timespec *__restrict t1,
75 const struct timespec *__restrict t2)
76{
77 if (t1->tv_sec < t2->tv_sec)
78 return 1;
79
80 if (t1->tv_sec == t2->tv_sec &&
81 t1->tv_nsec <= t2->tv_nsec)
82 return 1;
83
84 return 0;
85}
86
87static inline int __attribute__ ((always_inline))
88timespec_after(const struct timespec *__restrict t1,
89 const struct timespec *__restrict t2)
90{
91 return !timespec_before_or_same(t1, t2);
92}
93
94static inline int __attribute__ ((always_inline))
95timespec_after_or_same(const struct timespec *__restrict t1,
96 const struct timespec *__restrict t2)
97{
98 return !timespec_before(t1, t2);
99}
100
101#endif /* _BOILERPLATE_TIME_H */