aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/iomgr/timer_generic.cc
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-12-06 09:05:05 -0800
committerGravatar GitHub <noreply@github.com>2017-12-06 09:05:05 -0800
commitad4d2dde0052efbbf49d64b0843c45f0381cfeb3 (patch)
tree6a657f8c6179d873b34505cdc24bce9462ca68eb /src/core/lib/iomgr/timer_generic.cc
parenta3df36cc2505a89c2f481eea4a66a87b3002844a (diff)
Revert "All instances of exec_ctx being passed around in src/core removed"
Diffstat (limited to 'src/core/lib/iomgr/timer_generic.cc')
-rw-r--r--src/core/lib/iomgr/timer_generic.cc47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc
index 103144eb3b..fa95c43dbe 100644
--- a/src/core/lib/iomgr/timer_generic.cc
+++ b/src/core/lib/iomgr/timer_generic.cc
@@ -225,7 +225,8 @@ static gpr_atm saturating_add(gpr_atm a, gpr_atm b) {
return a + b;
}
-static grpc_timer_check_result run_some_expired_timers(gpr_atm now,
+static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx,
+ gpr_atm now,
gpr_atm* next,
grpc_error* error);
@@ -235,7 +236,7 @@ static gpr_atm compute_min_deadline(timer_shard* shard) {
: grpc_timer_heap_top(&shard->heap)->deadline;
}
-void grpc_timer_list_init() {
+void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) {
uint32_t i;
g_num_shards = GPR_MIN(1, 2 * gpr_cpu_num_cores());
@@ -246,7 +247,7 @@ void grpc_timer_list_init() {
g_shared_mutables.initialized = true;
g_shared_mutables.checker_mu = GPR_SPINLOCK_INITIALIZER;
gpr_mu_init(&g_shared_mutables.mu);
- g_shared_mutables.min_timer = grpc_core::ExecCtx::Get()->Now();
+ g_shared_mutables.min_timer = grpc_exec_ctx_now(exec_ctx);
gpr_tls_init(&g_last_seen_min_timer);
gpr_tls_set(&g_last_seen_min_timer, 0);
@@ -266,10 +267,10 @@ void grpc_timer_list_init() {
INIT_TIMER_HASH_TABLE();
}
-void grpc_timer_list_shutdown() {
+void grpc_timer_list_shutdown(grpc_exec_ctx* exec_ctx) {
size_t i;
run_some_expired_timers(
- GPR_ATM_MAX, nullptr,
+ exec_ctx, GPR_ATM_MAX, nullptr,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Timer list shutdown"));
for (i = 0; i < g_num_shards; i++) {
timer_shard* shard = &g_shards[i];
@@ -322,8 +323,8 @@ static void note_deadline_change(timer_shard* shard) {
void grpc_timer_init_unset(grpc_timer* timer) { timer->pending = false; }
-void grpc_timer_init(grpc_timer* timer, grpc_millis deadline,
- grpc_closure* closure) {
+void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer,
+ grpc_millis deadline, grpc_closure* closure) {
int is_first_timer = 0;
timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)];
timer->closure = closure;
@@ -336,12 +337,12 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline,
if (grpc_timer_trace.enabled()) {
gpr_log(GPR_DEBUG,
"TIMER %p: SET %" PRIdPTR " now %" PRIdPTR " call %p[%p]", timer,
- deadline, grpc_core::ExecCtx::Get()->Now(), closure, closure->cb);
+ deadline, grpc_exec_ctx_now(exec_ctx), closure, closure->cb);
}
if (!g_shared_mutables.initialized) {
timer->pending = false;
- GRPC_CLOSURE_SCHED(timer->closure,
+ GRPC_CLOSURE_SCHED(exec_ctx, timer->closure,
GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Attempt to create timer before initialization"));
return;
@@ -349,10 +350,10 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline,
gpr_mu_lock(&shard->mu);
timer->pending = true;
- grpc_millis now = grpc_core::ExecCtx::Get()->Now();
+ grpc_millis now = grpc_exec_ctx_now(exec_ctx);
if (deadline <= now) {
timer->pending = false;
- GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_NONE);
gpr_mu_unlock(&shard->mu);
/* early out */
return;
@@ -413,7 +414,7 @@ void grpc_timer_consume_kick(void) {
gpr_tls_set(&g_last_seen_min_timer, 0);
}
-void grpc_timer_cancel(grpc_timer* timer) {
+void grpc_timer_cancel(grpc_exec_ctx* exec_ctx, grpc_timer* timer) {
if (!g_shared_mutables.initialized) {
/* must have already been cancelled, also the shard mutex is invalid */
return;
@@ -429,7 +430,7 @@ void grpc_timer_cancel(grpc_timer* timer) {
if (timer->pending) {
REMOVE_FROM_HASH_TABLE(timer);
- GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_CANCELLED);
+ GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_CANCELLED);
timer->pending = false;
if (timer->heap_index == INVALID_HEAP_INDEX) {
list_remove(timer);
@@ -515,14 +516,15 @@ static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) {
}
/* REQUIRES: shard->mu unlocked */
-static size_t pop_timers(timer_shard* shard, gpr_atm now,
- gpr_atm* new_min_deadline, grpc_error* error) {
+static size_t pop_timers(grpc_exec_ctx* exec_ctx, timer_shard* shard,
+ gpr_atm now, gpr_atm* new_min_deadline,
+ grpc_error* error) {
size_t n = 0;
grpc_timer* timer;
gpr_mu_lock(&shard->mu);
while ((timer = pop_one(shard, now))) {
REMOVE_FROM_HASH_TABLE(timer);
- GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_REF(error));
+ GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_REF(error));
n++;
}
*new_min_deadline = compute_min_deadline(shard);
@@ -534,7 +536,8 @@ static size_t pop_timers(timer_shard* shard, gpr_atm now,
return n;
}
-static grpc_timer_check_result run_some_expired_timers(gpr_atm now,
+static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx,
+ gpr_atm now,
gpr_atm* next,
grpc_error* error) {
grpc_timer_check_result result = GRPC_TIMERS_NOT_CHECKED;
@@ -563,7 +566,8 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now,
/* For efficiency, we pop as many available timers as we can from the
shard. This may violate perfect timer deadline ordering, but that
shouldn't be a big deal because we don't make ordering guarantees. */
- if (pop_timers(g_shard_queue[0], now, &new_min_deadline, error) > 0) {
+ if (pop_timers(exec_ctx, g_shard_queue[0], now, &new_min_deadline,
+ error) > 0) {
result = GRPC_TIMERS_FIRED;
}
@@ -600,9 +604,10 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now,
return result;
}
-grpc_timer_check_result grpc_timer_check(grpc_millis* next) {
+grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx,
+ grpc_millis* next) {
// prelude
- grpc_millis now = grpc_core::ExecCtx::Get()->Now();
+ grpc_millis now = grpc_exec_ctx_now(exec_ctx);
/* fetch from a thread-local first: this avoids contention on a globally
mutable cacheline in the common case */
@@ -641,7 +646,7 @@ grpc_timer_check_result grpc_timer_check(grpc_millis* next) {
}
// actual code
grpc_timer_check_result r =
- run_some_expired_timers(now, next, shutdown_error);
+ run_some_expired_timers(exec_ctx, now, next, shutdown_error);
// tracing
if (grpc_timer_check_trace.enabled()) {
char* next_str;