Lely core libraries  2.3.4
clock.c
Go to the documentation of this file.
1 
24 #include "../io2.h"
25 #include <lely/io2/sys/clock.h>
26 
27 #ifdef CLOCK_REALTIME
28 
29 static int io_clock_realtime_getres(
30  const io_clock_t *clock, struct timespec *res);
31 static int io_clock_realtime_gettime(
32  const io_clock_t *clock, struct timespec *tp);
33 static int io_clock_realtime_settime(
34  io_clock_t *clock, const struct timespec *tp);
35 
36 // clang-format off
37 static const struct io_clock_vtbl io_clock_realtime_vtbl = {
38  &io_clock_realtime_getres,
39  &io_clock_realtime_gettime,
40  &io_clock_realtime_settime
41 };
42 // clang-format on
43 
44 const struct io_clock_realtime io_clock_realtime = { &io_clock_realtime_vtbl };
45 
46 #endif // CLOCK_REALTIME
47 
48 #ifdef CLOCK_MONOTONIC
49 
50 static int io_clock_monotonic_getres(
51  const io_clock_t *clock, struct timespec *res);
52 static int io_clock_monotonic_gettime(
53  const io_clock_t *clock, struct timespec *tp);
54 static int io_clock_monotonic_settime(
55  io_clock_t *clock, const struct timespec *tp);
56 
57 // clang-format off
58 static const struct io_clock_vtbl io_clock_monotonic_vtbl = {
59  &io_clock_monotonic_getres,
60  &io_clock_monotonic_gettime,
61  &io_clock_monotonic_settime
62 };
63 // clang-format on
64 
66  &io_clock_monotonic_vtbl
67 };
68 
69 #endif // CLOCK_MONOTONIC
70 
71 #ifdef CLOCK_REALTIME
72 
73 static int
74 io_clock_realtime_getres(const io_clock_t *clock, struct timespec *res)
75 {
76  (void)clock;
77 
78  return clock_getres(CLOCK_REALTIME, res);
79 }
80 
81 static int
82 io_clock_realtime_gettime(const io_clock_t *clock, struct timespec *tp)
83 {
84  (void)clock;
85 
86  return clock_gettime(CLOCK_REALTIME, tp);
87 }
88 
89 static int
90 io_clock_realtime_settime(io_clock_t *clock, const struct timespec *tp)
91 {
92  (void)clock;
93 
94  return clock_settime(CLOCK_REALTIME, tp);
95 }
96 
97 #endif // CLOCK_REALTIME
98 
99 #ifdef CLOCK_MONOTONIC
100 
101 static int
102 io_clock_monotonic_getres(const io_clock_t *clock, struct timespec *res)
103 {
104  (void)clock;
105 
106  return clock_getres(CLOCK_MONOTONIC, res);
107 }
108 
109 static int
110 io_clock_monotonic_gettime(const io_clock_t *clock, struct timespec *tp)
111 {
112  (void)clock;
113 
114  return clock_gettime(CLOCK_MONOTONIC, tp);
115 }
116 
117 static int
118 io_clock_monotonic_settime(io_clock_t *clock, const struct timespec *tp)
119 {
120  (void)clock;
121 
122  return clock_settime(CLOCK_MONOTONIC, tp);
123 }
124 
125 #endif // CLOCK_MONOTONIC
const struct io_clock_vtbl *const io_clock_t
An abstract clock.
Definition: clock.h:36
This header file is part of the I/O library; it contains the standard system clock definitions.