aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/iomgr/exec_ctx.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/iomgr/exec_ctx.cc')
-rw-r--r--src/core/lib/iomgr/exec_ctx.cc98
1 files changed, 29 insertions, 69 deletions
diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc
index c10d1e60f0..fe5a0e7e2d 100644
--- a/src/core/lib/iomgr/exec_ctx.cc
+++ b/src/core/lib/iomgr/exec_ctx.cc
@@ -27,45 +27,19 @@
thread_local ExecCtx* exec_ctx = nullptr;
-ExecCtx::ExecCtx()
- : closure_list(GRPC_CLOSURE_LIST_INIT),
- active_combiner(nullptr),
- last_combiner(nullptr),
- flags(GRPC_EXEC_CTX_FLAG_IS_FINISHED),
- starting_cpu(gpr_cpu_current_cpu()),
- check_ready_to_finish_arg(nullptr),
- check_ready_to_finish(nullptr),
- now_is_valid(false),
- now(0),
- last_exec_ctx(exec_ctx) {
- exec_ctx = this;
-}
-
-ExecCtx::ExecCtx(uintptr_t fl, bool (*finish_check)(void* arg),
- void* finish_check_arg)
- : closure_list(GRPC_CLOSURE_LIST_INIT),
- active_combiner(nullptr),
- last_combiner(nullptr),
- flags(fl),
- starting_cpu(gpr_cpu_current_cpu()),
- check_ready_to_finish_arg(finish_check_arg),
- check_ready_to_finish(finish_check),
- now_is_valid(false),
- now(0),
- last_exec_ctx(exec_ctx) {
- exec_ctx = this;
-}
-
+ExecCtx::ExecCtx() : flags_(GRPC_EXEC_CTX_FLAG_IS_FINISHED) { exec_ctx = this; }
+ExecCtx::ExecCtx(uintptr_t fl) : flags_(fl) { exec_ctx = this; }
ExecCtx::~ExecCtx() {
GPR_ASSERT(exec_ctx == this);
- grpc_exec_ctx_finish();
- exec_ctx = last_exec_ctx;
+ flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED;
+ Flush();
+ exec_ctx = last_exec_ctx_;
}
-bool grpc_exec_ctx_ready_to_finish() {
- if ((exec_ctx->flags & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) {
- if (exec_ctx->check_ready_to_finish(exec_ctx->check_ready_to_finish_arg)) {
- exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED;
+bool ExecCtx::IsReadyToFinish() {
+ if ((flags_ & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) {
+ if (CheckReadyToFinish()) {
+ flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED;
return true;
}
return false;
@@ -74,21 +48,7 @@ bool grpc_exec_ctx_ready_to_finish() {
}
}
-bool grpc_never_ready_to_finish(void* arg_ignored) { return false; }
-
-bool grpc_always_ready_to_finish(void* arg_ignored) { return true; }
-
-bool grpc_exec_ctx_has_work() {
- return exec_ctx->active_combiner != NULL ||
- !grpc_closure_list_empty(exec_ctx->closure_list);
-}
-
-void grpc_exec_ctx_finish() {
- exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED;
- grpc_exec_ctx_flush();
-}
-
-static void exec_ctx_run(grpc_closure* closure, grpc_error* error) {
+void exec_ctx_run(grpc_closure* closure, grpc_error* error) {
#ifndef NDEBUG
closure->scheduled = false;
if (GRPC_TRACER_ON(grpc_trace_closure)) {
@@ -107,13 +67,13 @@ static void exec_ctx_run(grpc_closure* closure, grpc_error* error) {
GRPC_ERROR_UNREF(error);
}
-bool grpc_exec_ctx_flush() {
+bool ExecCtx::Flush() {
bool did_something = 0;
GPR_TIMER_BEGIN("grpc_exec_ctx_flush", 0);
for (;;) {
- if (!grpc_closure_list_empty(exec_ctx->closure_list)) {
- grpc_closure* c = exec_ctx->closure_list.head;
- exec_ctx->closure_list.head = exec_ctx->closure_list.tail = NULL;
+ if (!grpc_closure_list_empty(closure_list_)) {
+ grpc_closure* c = closure_list_.head;
+ closure_list_.head = closure_list_.tail = NULL;
while (c != NULL) {
grpc_closure* next = c->next_data.next;
grpc_error* error = c->error_data.error;
@@ -125,13 +85,13 @@ bool grpc_exec_ctx_flush() {
break;
}
}
- GPR_ASSERT(exec_ctx->active_combiner == NULL);
+ GPR_ASSERT(combiner_data_.active_combiner == nullptr);
GPR_TIMER_END("grpc_exec_ctx_flush", 0);
return did_something;
}
-static void exec_ctx_sched(grpc_closure* closure, grpc_error* error) {
- grpc_closure_list_append(&exec_ctx->closure_list, closure, error);
+void exec_ctx_sched(grpc_closure* closure, grpc_error* error) {
+ grpc_closure_list_append(exec_ctx->closure_list(), closure, error);
}
static gpr_timespec
@@ -139,7 +99,7 @@ static gpr_timespec
// last enum value in
// gpr_clock_type
-void grpc_exec_ctx_global_init(void) {
+void ExecCtx::GlobalInit(void) {
for (int i = 0; i < GPR_TIMESPAN; i++) {
g_start_time[i] = gpr_now((gpr_clock_type)i);
}
@@ -147,7 +107,7 @@ void grpc_exec_ctx_global_init(void) {
g_start_time[GPR_TIMESPAN] = gpr_time_0(GPR_TIMESPAN);
}
-void grpc_exec_ctx_global_shutdown(void) {}
+void ExecCtx::GlobalShutdown(void) {}
static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) {
ts = gpr_time_sub(ts, g_start_time[ts.clock_type]);
@@ -168,16 +128,6 @@ static gpr_atm timespec_to_atm_round_up(gpr_timespec ts) {
return (gpr_atm)x;
}
-grpc_millis grpc_exec_ctx_now() {
- if (!exec_ctx->now_is_valid) {
- exec_ctx->now = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC));
- exec_ctx->now_is_valid = true;
- }
- return exec_ctx->now;
-}
-
-void grpc_exec_ctx_invalidate_now() { exec_ctx->now_is_valid = false; }
-
gpr_timespec grpc_millis_to_timespec(grpc_millis millis,
gpr_clock_type clock_type) {
// special-case infinities as grpc_millis can be 32bit on some platforms
@@ -204,6 +154,16 @@ grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec ts) {
return timespec_to_atm_round_up(ts);
}
+grpc_millis ExecCtx::Now() {
+ if (!now_is_valid_) {
+ now_ = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC));
+ now_is_valid_ = true;
+ }
+ return now_;
+}
+
+ExecCtx* ExecCtx::Get() { return exec_ctx; }
+
static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = {
exec_ctx_run, exec_ctx_sched, "exec_ctx"};
static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable};