Xenomai  3.1
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 
23 typedef unsigned long long ticks_t;
24 
25 typedef long long sticks_t;
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 void timespec_sub(struct timespec *__restrict r,
32  const struct timespec *__restrict t1,
33  const struct timespec *__restrict t2);
34 
35 void timespec_subs(struct timespec *__restrict r,
36  const struct timespec *__restrict t1,
37  sticks_t t2);
38 
39 void timespec_add(struct timespec *__restrict r,
40  const struct timespec *__restrict t1,
41  const struct timespec *__restrict t2);
42 
43 void timespec_adds(struct timespec *__restrict r,
44  const struct timespec *__restrict t1,
45  sticks_t t2);
46 
47 void timespec_sets(struct timespec *__restrict r,
48  ticks_t ns);
49 
50 #ifdef __cplusplus
51 }
52 #endif
53 
54 static inline sticks_t timespec_scalar(const struct timespec *__restrict t)
55 {
56  return t->tv_sec * 1000000000LL + t->tv_nsec;
57 }
58 
59 static inline int __attribute__ ((always_inline))
60 timespec_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 
73 static inline int __attribute__ ((always_inline))
74 timespec_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 
87 static inline int __attribute__ ((always_inline))
88 timespec_after(const struct timespec *__restrict t1,
89  const struct timespec *__restrict t2)
90 {
91  return !timespec_before_or_same(t1, t2);
92 }
93 
94 static inline int __attribute__ ((always_inline))
95 timespec_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 */
static int __attribute__((cold))
Test if a mutex structure contains a valid autoinitializer.
Definition: mutex.c:177