Adding ExecCtx::Run

reviewable/pr20892/r1
Yash Tibrewal 5 years ago
parent ce842ecc31
commit 336b476d32
  1. 38
      src/core/lib/iomgr/closure.h
  2. 22
      src/core/lib/iomgr/exec_ctx.cc
  3. 4
      src/core/lib/iomgr/exec_ctx.h

@ -277,44 +277,6 @@ inline void grpc_closure_run(grpc_closure* c, grpc_error* error) {
#define GRPC_CLOSURE_RUN(closure, error) grpc_closure_run(closure, error)
#endif
#ifndef NDEBUG
inline void grpc_closure_sched(const char* file, int line, grpc_closure* c,
grpc_error* error) {
#else
inline void grpc_closure_sched(grpc_closure* c, grpc_error* error) {
#endif
GPR_TIMER_SCOPE("grpc_closure_sched", 0);
if (c != nullptr) {
#ifndef NDEBUG
if (c->scheduled) {
gpr_log(GPR_ERROR,
"Closure already scheduled. (closure: %p, created: [%s:%d], "
"previously scheduled at: [%s: %d], newly scheduled at [%s: %d], "
"run?: %s",
c, c->file_created, c->line_created, c->file_initiated,
c->line_initiated, file, line, c->run ? "true" : "false");
abort();
}
c->scheduled = true;
c->file_initiated = file;
c->line_initiated = line;
c->run = false;
GPR_ASSERT(c->cb != nullptr);
#endif
c->scheduler->vtable->sched(c, error);
} else {
GRPC_ERROR_UNREF(error);
}
}
/** Schedule a closure to be run. Does not need to be run from a safe point. */
#ifndef NDEBUG
#define GRPC_CLOSURE_SCHED(closure, error) \
grpc_closure_sched(__FILE__, __LINE__, closure, error)
#else
#define GRPC_CLOSURE_SCHED(closure, error) grpc_closure_sched(closure, error)
#endif
#ifndef NDEBUG
inline void grpc_closure_list_sched(const char* file, int line,
grpc_closure_list* list) {

@ -174,4 +174,26 @@ grpc_millis ExecCtx::Now() {
return now_;
}
void ExecCtx::Run(const DebugLocation& location, grpc_closure* closure,
grpc_error* error) {
#ifndef NDEBUG
if (closure->scheduled) {
gpr_log(GPR_ERROR,
"Closure already scheduled. (closure: %p, created: [%s:%d], "
"previously scheduled at: [%s: %d], newly scheduled at [%s: %d], "
"run?: %s",
closure, closure->file_created, closure->line_created,
closure->file_initiated, closure->line_initiated, location.file(),
location.line(), closure->run ? "true" : "false");
abort();
}
closure->scheduled = true;
closure->file_initiated = file;
closure->line_initiated = line;
closure->run = false;
GPR_ASSERT(closure->cb != nullptr);
#endif
exec_ctx_sched(closure, error);
}
} // namespace grpc_core

@ -28,6 +28,7 @@
#include "src/core/lib/gpr/time_precise.h"
#include "src/core/lib/gpr/tls.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/fork.h"
#include "src/core/lib/iomgr/closure.h"
@ -221,6 +222,9 @@ class ExecCtx {
gpr_tls_set(&exec_ctx_, reinterpret_cast<intptr_t>(exec_ctx));
}
static void Run(const DebugLocation& location, grpc_closure* closure,
grpc_error* error);
protected:
/** Check if ready to finish. */
virtual bool CheckReadyToFinish() { return false; }

Loading…
Cancel
Save