diff options
author | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2016-02-02 10:23:15 -0800 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2016-02-02 10:23:15 -0800 |
commit | 4d48522f0075884b2b57ff24a65fee76b918e52f (patch) | |
tree | 9004833316149f0004efca27dac085367726711f /src/core | |
parent | ac91ec58eeb76745b1c33d23ed7e6b80217565a1 (diff) | |
parent | 954e94655e82671208e6d01d9db5aeecda3f86d9 (diff) |
Merge pull request #4998 from ctiller/syscall
Make clock_gettime syscall directly to skirt ABI issues
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/support/time_posix.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c index 06bb78c913..1f92d7f090 100644 --- a/src/core/support/time_posix.c +++ b/src/core/support/time_posix.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -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 { +#if defined(__linux__) && !defined(GPR_NO_DIRECT_SYSCALLS) + /* 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); } } |