*/
#include <assert.h>
-#include <time.h>
+#include <common/compat/time.h>
#include <pthread.h>
#include <urcu/tls-compat.h>
#include <urcu/uatomic.h>
pthread_mutex_lock(&consumer_data->cond_mutex);
/* Get time for sem_timedwait absolute timeout */
- clock_ret = clock_gettime(CLOCK_MONOTONIC, &timeout);
+ clock_ret = lttng_clock_gettime(CLOCK_MONOTONIC, &timeout);
/*
* Set the timeout for the condition timed wait even if the clock gettime
* call fails since we might loop on that call and we want to avoid to
#ifndef _UST_CLOCK_H
#define _UST_CLOCK_H
-#include <time.h>
+#include <common/compat/time.h>
#include <sys/time.h>
#include <stdint.h>
#include <stddef.h>
{
struct timespec ts;
- if (clock_gettime(CLOCK_MONOTONIC, &ts)) {
+ if (lttng_clock_gettime(CLOCK_MONOTONIC, &ts)) {
/* TODO Report error cleanly up the chain. */
PERROR("clock_gettime CLOCK_MONOTONIC");
ts.tv_sec = 0;
int ret;
monotonic[0] = trace_clock_read64();
- ret = clock_gettime(CLOCK_REALTIME, &rts);
+ ret = lttng_clock_gettime(CLOCK_REALTIME, &rts);
if (ret < 0) {
return ret;
}
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <time.h>
+#include <common/compat/time.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
libcompat_la_SOURCES = poll.h fcntl.h endian.h mman.h dirent.h \
socket.h compat-fcntl.c uuid.h tid.h \
- getenv.h string.h prctl.h paths.h netdb.h $(COMPAT)
+ getenv.h string.h prctl.h paths.h netdb.h $(COMPAT) \
+ time.h
--- /dev/null
+/*
+ * Copyright (C) 2016 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef _COMPAT_TIME_H
+#define _COMPAT_TIME_H
+
+#include <time.h>
+
+#ifdef __APPLE__
+typedef uint64_t timer_t;
+typedef int clockid_t;
+
+#include <mach/mach.h>
+#include <mach/clock.h>
+
+#define CLOCK_REALTIME CALENDAR_CLOCK
+#define CLOCK_MONOTONIC SYSTEM_CLOCK
+
+static inline
+int lttng_clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+ int ret = 0;
+ clock_serv_t clock;
+ mach_timespec_t now;
+
+ if (clk_id != CLOCK_REALTIME && clk_id != CLOCK_MONOTONIC) {
+ ret = -1;
+ errno = EINVAL;
+ goto end;
+ }
+
+ host_get_clock_service(mach_host_self(), clk_id, &clock);
+
+ ret = clock_get_time(clock, &now);
+ if (ret != KERN_SUCCESS) {
+ ret = -1;
+ goto deallocate;
+ }
+
+ tp->tv_sec = now.tv_sec;
+ tp->tv_nsec = now.tv_nsec;
+
+deallocate:
+ mach_port_deallocate(mach_task_self(), clock);
+end:
+ return ret;
+}
+
+#else /* __APPLE__ */
+
+static inline
+int lttng_clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+ return clock_gettime(clk_id, tp);
+}
+
+#endif /* __APPLE__ */
+
+#endif /* _COMPAT_TIME_H */
struct timespec tp;
time_t now;
- ret = clock_gettime(CLOCK_REALTIME, &tp);
+ ret = lttng_clock_gettime(CLOCK_REALTIME, &tp);
if (ret < 0) {
goto error;
}
#include <string.h>
#include <stdbool.h>
#include <urcu/tls-compat.h>
-#include <time.h>
+#include <common/compat/time.h>
#ifndef _GNU_SOURCE
#error "lttng-tools error.h needs _GNU_SOURCE"
last = state->last;
current = uatomic_read(&state->current);
- ret = clock_gettime(CLOCK_MONOTONIC, ¤t_time);
+ ret = lttng_clock_gettime(CLOCK_MONOTONIC, ¤t_time);
if (ret < 0) {
PERROR("Error reading time\n");
/* error */
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
-#include <time.h>
+#include <common/compat/time.h>
#include <poll.h>
#include <common/common.h>
return -1;
}
- ret = clock_gettime(CLOCK_MONOTONIC, &orig_time);
+ ret = lttng_clock_gettime(CLOCK_MONOTONIC, &orig_time);
if (ret == -1) {
PERROR("clock_gettime");
return -1;
}
}
/* ret == 0: timeout */
- ret = clock_gettime(CLOCK_MONOTONIC, &cur_time);
+ ret = lttng_clock_gettime(CLOCK_MONOTONIC, &cur_time);
if (ret == -1) {
PERROR("clock_gettime");
connect_ret = ret;
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
-#include <time.h>
+#include <common/compat/time.h>
#include <poll.h>
#include <common/common.h>
return -1;
}
- ret = clock_gettime(CLOCK_MONOTONIC, &orig_time);
+ ret = lttng_clock_gettime(CLOCK_MONOTONIC, &orig_time);
if (ret == -1) {
PERROR("clock_gettime");
return -1;
}
}
/* ret == 0: timeout */
- ret = clock_gettime(CLOCK_MONOTONIC, &cur_time);
+ ret = lttng_clock_gettime(CLOCK_MONOTONIC, &cur_time);
if (ret == -1) {
PERROR("clock_gettime");
connect_ret = ret;
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src
EXTRA_DIST = test_event_basic test_all_events test_syscall \
test_clock_override test_rotation_destroy_flush \
test_select_poll_epoll
#include <limits.h>
#include <pthread.h>
#include <sys/mman.h>
-#include <time.h>
+#include <common/compat/time.h>
#define BUF_SIZE 256
#define NB_FD 1
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <time.h>
+#include <common/compat/time.h>
#include <sys/types.h>
#include <inttypes.h>
#include <stdlib.h>
*/
#include <stdlib.h>
-#include <time.h>
+#include <common/compat/time.h>
#include <string.h>
#include <stdio.h>
#include <lttng/ust-clock.h>
*/
#include <stdlib.h>
-#include <time.h>
+#include <common/compat/time.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
SUBDIRS = . tap testapp
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src
EXTRA_DIST = utils.sh test_utils.py babelstats.pl warn_processes.sh
dist_noinst_SCRIPTS = utils.sh test_utils.py babelstats.pl
noinst_LTLIBRARIES = libtestutils.la
*/
#include <stdint.h>
-#include <time.h>
+#include <common/compat/time.h>
#include <assert.h>
#include <unistd.h>
#include <stdio.h>
struct timespec t1, t2;
int64_t time_remaining_ns = (int64_t) usec * (int64_t) NSEC_PER_USEC;
- ret = clock_gettime(CLOCK_MONOTONIC, &t1);
+ ret = lttng_clock_gettime(CLOCK_MONOTONIC, &t1);
if (ret) {
ret = -1;
perror("clock_gettime");