diff options
author | 2016-10-16 22:36:02 -0700 | |
---|---|---|
committer | 2017-11-16 14:50:59 -0800 | |
commit | 5dca5bf644afc3df624f4c97c406a66b149df6f4 (patch) | |
tree | e77ec87387d1d107a345ff62fe3c27dc17386917 /src/core/lib/support/sync_posix.cc | |
parent | ad3bdbeb4a2e9d411b07f4bc008a5b2f8274be40 (diff) |
sync_posix: Add Linux-specific monotonic clock preference
When gRPC is running during wall clock acquisition, it's useful
to avoid wall clock references as much as possible.
Diffstat (limited to 'src/core/lib/support/sync_posix.cc')
-rw-r--r-- | src/core/lib/support/sync_posix.cc | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/core/lib/support/sync_posix.cc b/src/core/lib/support/sync_posix.cc index dfdd233bf4..c3f6b10463 100644 --- a/src/core/lib/support/sync_posix.cc +++ b/src/core/lib/support/sync_posix.cc @@ -66,7 +66,12 @@ int gpr_mu_trylock(gpr_mu* mu) { /*----------------------------------------*/ void gpr_cv_init(gpr_cv* cv) { - GPR_ASSERT(pthread_cond_init(cv, nullptr) == 0); + pthread_condattr_t attr; + GPR_ASSERT(pthread_condattr_init(&attr) == 0); +#if GPR_LINUX + GPR_ASSERT(pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0); +#endif // GPR_LINUX + GPR_ASSERT(pthread_cond_init(cv, &attr) == 0); } void gpr_cv_destroy(gpr_cv* cv) { GPR_ASSERT(pthread_cond_destroy(cv) == 0); } @@ -78,7 +83,11 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) { err = pthread_cond_wait(cv, mu); } else { struct timespec abs_deadline_ts; +#if GPR_LINUX + abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_MONOTONIC); +#else abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_REALTIME); +#endif // GPR_LINUX abs_deadline_ts.tv_sec = (time_t)abs_deadline.tv_sec; abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec; err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts); |