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
29static int io_clock_realtime_getres(
30 const io_clock_t *clock, struct timespec *res);
31static int io_clock_realtime_gettime(
32 const io_clock_t *clock, struct timespec *tp);
33static int io_clock_realtime_settime(
34 io_clock_t *clock, const struct timespec *tp);
35
36// clang-format off
37static 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
44const struct io_clock_realtime io_clock_realtime = { &io_clock_realtime_vtbl };
45
46#endif // CLOCK_REALTIME
47
48#ifdef CLOCK_MONOTONIC
49
50static int io_clock_monotonic_getres(
51 const io_clock_t *clock, struct timespec *res);
52static int io_clock_monotonic_gettime(
53 const io_clock_t *clock, struct timespec *tp);
54static int io_clock_monotonic_settime(
55 io_clock_t *clock, const struct timespec *tp);
56
57// clang-format off
58static 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
73static int
74io_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
81static int
82io_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
89static int
90io_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
101static int
102io_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
109static int
110io_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
117static int
118io_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.