aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-02-01 14:34:00 -0800
committerGravatar Craig Tiller <ctiller@google.com>2016-02-01 14:34:00 -0800
commit22a913929661db9a39e51d706700db4516ce7aa9 (patch)
treeac8e78530e1f227a4b5b1482e82920c406f12480
parent6d7ae08a3376377e11f8e3fe043e0b45dbde48aa (diff)
Make clock_gettime syscall directly to skirt ABI issues
-rw-r--r--src/core/support/time_posix.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c
index 06bb78c913..a868281058 100644
--- a/src/core/support/time_posix.c
+++ b/src/core/support/time_posix.c
@@ -39,6 +39,9 @@
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
+#ifdef __linux__
+#include <sys/syscall.h>
+#endif
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#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);
}
}