diff options
Diffstat (limited to 'src/core/support/sync_posix.c')
-rw-r--r-- | src/core/support/sync_posix.c | 90 |
1 files changed, 26 insertions, 64 deletions
diff --git a/src/core/support/sync_posix.c b/src/core/support/sync_posix.c index e7ca7e01d4..91c30989ce 100644 --- a/src/core/support/sync_posix.c +++ b/src/core/support/sync_posix.c @@ -41,90 +41,52 @@ #include <grpc/support/sync.h> #include <grpc/support/time.h> -void -gpr_mu_init (gpr_mu * mu) -{ - GPR_ASSERT (pthread_mutex_init (mu, NULL) == 0); -} +void gpr_mu_init(gpr_mu* mu) { GPR_ASSERT(pthread_mutex_init(mu, NULL) == 0); } -void -gpr_mu_destroy (gpr_mu * mu) -{ - GPR_ASSERT (pthread_mutex_destroy (mu) == 0); -} +void gpr_mu_destroy(gpr_mu* mu) { GPR_ASSERT(pthread_mutex_destroy(mu) == 0); } -void -gpr_mu_lock (gpr_mu * mu) -{ - GPR_ASSERT (pthread_mutex_lock (mu) == 0); -} +void gpr_mu_lock(gpr_mu* mu) { GPR_ASSERT(pthread_mutex_lock(mu) == 0); } -void -gpr_mu_unlock (gpr_mu * mu) -{ - GPR_ASSERT (pthread_mutex_unlock (mu) == 0); -} +void gpr_mu_unlock(gpr_mu* mu) { GPR_ASSERT(pthread_mutex_unlock(mu) == 0); } -int -gpr_mu_trylock (gpr_mu * mu) -{ - int err = pthread_mutex_trylock (mu); - GPR_ASSERT (err == 0 || err == EBUSY); +int gpr_mu_trylock(gpr_mu* mu) { + int err = pthread_mutex_trylock(mu); + GPR_ASSERT(err == 0 || err == EBUSY); return err == 0; } /*----------------------------------------*/ -void -gpr_cv_init (gpr_cv * cv) -{ - GPR_ASSERT (pthread_cond_init (cv, NULL) == 0); -} +void gpr_cv_init(gpr_cv* cv) { GPR_ASSERT(pthread_cond_init(cv, NULL) == 0); } -void -gpr_cv_destroy (gpr_cv * cv) -{ - GPR_ASSERT (pthread_cond_destroy (cv) == 0); -} +void gpr_cv_destroy(gpr_cv* cv) { GPR_ASSERT(pthread_cond_destroy(cv) == 0); } -int -gpr_cv_wait (gpr_cv * cv, gpr_mu * mu, gpr_timespec abs_deadline) -{ +int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) { int err = 0; - if (gpr_time_cmp (abs_deadline, gpr_inf_future (abs_deadline.clock_type)) == 0) - { - err = pthread_cond_wait (cv, mu); - } - else - { - struct timespec abs_deadline_ts; - abs_deadline = gpr_convert_clock_type (abs_deadline, GPR_CLOCK_REALTIME); - abs_deadline_ts.tv_sec = abs_deadline.tv_sec; - abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec; - err = pthread_cond_timedwait (cv, mu, &abs_deadline_ts); - } - GPR_ASSERT (err == 0 || err == ETIMEDOUT || err == EAGAIN); + if (gpr_time_cmp(abs_deadline, gpr_inf_future(abs_deadline.clock_type)) == + 0) { + err = pthread_cond_wait(cv, mu); + } else { + struct timespec abs_deadline_ts; + abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_REALTIME); + abs_deadline_ts.tv_sec = abs_deadline.tv_sec; + abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec; + err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts); + } + GPR_ASSERT(err == 0 || err == ETIMEDOUT || err == EAGAIN); return err == ETIMEDOUT; } -void -gpr_cv_signal (gpr_cv * cv) -{ - GPR_ASSERT (pthread_cond_signal (cv) == 0); -} +void gpr_cv_signal(gpr_cv* cv) { GPR_ASSERT(pthread_cond_signal(cv) == 0); } -void -gpr_cv_broadcast (gpr_cv * cv) -{ - GPR_ASSERT (pthread_cond_broadcast (cv) == 0); +void gpr_cv_broadcast(gpr_cv* cv) { + GPR_ASSERT(pthread_cond_broadcast(cv) == 0); } /*----------------------------------------*/ -void -gpr_once_init (gpr_once * once, void (*init_function) (void)) -{ - GPR_ASSERT (pthread_once (once, init_function) == 0); +void gpr_once_init(gpr_once* once, void (*init_function)(void)) { + GPR_ASSERT(pthread_once(once, init_function) == 0); } #endif /* GRP_POSIX_SYNC */ |