|
|
|
@ -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); |
|
|
|
|