fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
[lttng-tools.git] / src / common / compat / time.hpp
1 /*
2 * Copyright (C) 2016 Michael Jeanson <mjeanson@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #ifndef _COMPAT_TIME_H
9 #define _COMPAT_TIME_H
10
11 #include <time.h>
12
13 #ifdef __APPLE__
14
15 #include <cstdint>
16
17 typedef uint64_t timer_t;
18
19 #include <common/compat/errno.hpp>
20
21 #include <mach/clock.h>
22 #include <mach/mach.h>
23
24 #undef NSEC_PER_SEC
25 #undef NSEC_PER_MSEC
26 #undef NSEC_PER_USEC
27 #undef USEC_PER_SEC
28
29 #endif /* __APPLE__ */
30
31 /* macOS/OS X 10.12 (Sierra) and up provide clock_gettime() */
32 #if defined(__APPLE__) && !defined(LTTNG_HAVE_CLOCK_GETTIME)
33
34 typedef int clockid_t;
35 #define CLOCK_REALTIME CALENDAR_CLOCK
36 #define CLOCK_MONOTONIC SYSTEM_CLOCK
37
38 static inline int lttng_clock_gettime(clockid_t clk_id, struct timespec *tp)
39 {
40 int ret = 0;
41 clock_serv_t clock;
42 mach_timespec_t now;
43
44 if (clk_id != CLOCK_REALTIME && clk_id != CLOCK_MONOTONIC) {
45 ret = -1;
46 errno = EINVAL;
47 goto end;
48 }
49
50 host_get_clock_service(mach_host_self(), clk_id, &clock);
51
52 ret = clock_get_time(clock, &now);
53 if (ret != KERN_SUCCESS) {
54 ret = -1;
55 goto deallocate;
56 }
57
58 tp->tv_sec = now.tv_sec;
59 tp->tv_nsec = now.tv_nsec;
60
61 deallocate:
62 mach_port_deallocate(mach_task_self(), clock);
63 end:
64 return ret;
65 }
66
67 #else /* __APPLE__ && !LTTNG_HAVE_CLOCK_GETTIME */
68
69 static inline int lttng_clock_gettime(clockid_t clk_id, struct timespec *tp)
70 {
71 return clock_gettime(clk_id, tp);
72 }
73
74 #endif /* __APPLE__ && !LTTNG_HAVE_CLOCK_GETTIME */
75
76 #endif /* _COMPAT_TIME_H */
This page took 0.030393 seconds and 4 git commands to generate.