From 22a913929661db9a39e51d706700db4516ce7aa9 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 1 Feb 2016 14:34:00 -0800 Subject: [PATCH] Make clock_gettime syscall directly to skirt ABI issues --- src/core/support/time_posix.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c index 06bb78c913b..a8682810582 100644 --- a/src/core/support/time_posix.c +++ b/src/core/support/time_posix.c @@ -39,6 +39,9 @@ #include #include #include +#ifdef __linux__ +#include +#endif #include #include #include "src/core/support/block_annotate.h" @@ -70,7 +73,8 @@ static gpr_timespec gpr_from_timespec(struct timespec ts, } /** maps gpr_clock_type --> clockid_t for clock_gettime */ -static clockid_t clockid_for_gpr_clock[] = {CLOCK_MONOTONIC, CLOCK_REALTIME}; +static const clockid_t clockid_for_gpr_clock[] = {CLOCK_MONOTONIC, + CLOCK_REALTIME}; void gpr_time_init(void) { gpr_precise_clock_init(); } @@ -82,7 +86,12 @@ gpr_timespec gpr_now(gpr_clock_type clock_type) { gpr_precise_clock_now(&ret); return ret; } else { +#ifdef __linux__ + /* avoid ABI problems by invoking syscalls directly */ + syscall(SYS_clock_gettime, clockid_for_gpr_clock[clock_type], &now); +#else clock_gettime(clockid_for_gpr_clock[clock_type], &now); +#endif return gpr_from_timespec(now, clock_type); } }