diff options
author | Yash Tibrewal <yashkt@google.com> | 2017-10-13 16:07:13 -0700 |
---|---|---|
committer | Yash Tibrewal <yashkt@google.com> | 2017-10-18 17:12:19 -0700 |
commit | 0ee7574732a06e8cace4e099a678f4bd5dbff679 (patch) | |
tree | e43d5de442fdcc3d39cd5af687f319fa39612d3f /src/core/lib/backoff | |
parent | 6bf5f833efe2cb9e2ecc14358dd9699cd5d05263 (diff) |
Removing instances of exec_ctx being passed around in functions in
src/core. exec_ctx is now a thread_local pointer of type ExecCtx instead of
grpc_exec_ctx which is initialized whenever ExecCtx is instantiated. ExecCtx
also keeps track of the previous exec_ctx so that nesting of exec_ctx is
allowed. This means that there is only one exec_ctx being used at any
time. Also, grpc_exec_ctx_finish is called in the destructor of the
object, and the previous exec_ctx is restored to avoid breaking current
functionality. The code still explicitly calls grpc_exec_ctx_finish
because removing all such instances causes the code to break.
Diffstat (limited to 'src/core/lib/backoff')
-rw-r--r-- | src/core/lib/backoff/backoff.cc | 10 | ||||
-rw-r--r-- | src/core/lib/backoff/backoff.h | 4 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/core/lib/backoff/backoff.cc b/src/core/lib/backoff/backoff.cc index fe0a751817..bb9388e3b4 100644 --- a/src/core/lib/backoff/backoff.cc +++ b/src/core/lib/backoff/backoff.cc @@ -32,11 +32,11 @@ void grpc_backoff_init(grpc_backoff *backoff, backoff->rng_state = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec; } -grpc_millis grpc_backoff_begin(grpc_exec_ctx *exec_ctx, grpc_backoff *backoff) { +grpc_millis grpc_backoff_begin(grpc_backoff *backoff) { backoff->current_timeout_millis = backoff->initial_connect_timeout; const grpc_millis first_timeout = GPR_MAX(backoff->current_timeout_millis, backoff->min_timeout_millis); - return grpc_exec_ctx_now(exec_ctx) + first_timeout; + return grpc_exec_ctx_now() + first_timeout; } /* Generate a random number between 0 and 1. */ @@ -45,7 +45,7 @@ static double generate_uniform_random_number(uint32_t *rng_state) { return *rng_state / (double)((uint32_t)1 << 31); } -grpc_millis grpc_backoff_step(grpc_exec_ctx *exec_ctx, grpc_backoff *backoff) { +grpc_millis grpc_backoff_step(grpc_backoff *backoff) { const double new_timeout_millis = backoff->multiplier * (double)backoff->current_timeout_millis; backoff->current_timeout_millis = @@ -60,10 +60,10 @@ grpc_millis grpc_backoff_step(grpc_exec_ctx *exec_ctx, grpc_backoff *backoff) { (grpc_millis)((double)(backoff->current_timeout_millis) + jitter); const grpc_millis current_deadline = - grpc_exec_ctx_now(exec_ctx) + backoff->current_timeout_millis; + grpc_exec_ctx_now() + backoff->current_timeout_millis; const grpc_millis min_deadline = - grpc_exec_ctx_now(exec_ctx) + backoff->min_timeout_millis; + grpc_exec_ctx_now() + backoff->min_timeout_millis; return GPR_MAX(current_deadline, min_deadline); } diff --git a/src/core/lib/backoff/backoff.h b/src/core/lib/backoff/backoff.h index 80e49ea52a..c48483758e 100644 --- a/src/core/lib/backoff/backoff.h +++ b/src/core/lib/backoff/backoff.h @@ -51,9 +51,9 @@ void grpc_backoff_init(grpc_backoff *backoff, grpc_millis max_timeout_millis); /// Begin retry loop: returns a timespec for the NEXT retry -grpc_millis grpc_backoff_begin(grpc_exec_ctx *exec_ctx, grpc_backoff *backoff); +grpc_millis grpc_backoff_begin(grpc_backoff *backoff); /// Step a retry loop: returns a timespec for the NEXT retry -grpc_millis grpc_backoff_step(grpc_exec_ctx *exec_ctx, grpc_backoff *backoff); +grpc_millis grpc_backoff_step(grpc_backoff *backoff); /// Reset the backoff, so the next grpc_backoff_step will be a /// grpc_backoff_begin /// instead |