19 #ifndef GRPC_CORE_LIB_IOMGR_EXEC_CTX_H
20 #define GRPC_CORE_LIB_IOMGR_EXEC_CTX_H
37 #define GRPC_MILLIS_INF_FUTURE INT64_MAX
38 #define GRPC_MILLIS_INF_PAST INT64_MIN
46 #define GRPC_EXEC_CTX_FLAG_IS_FINISHED 1
49 #define GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP 2
52 #define GRPC_EXEC_CTX_FLAG_IS_INTERNAL_THREAD 4
56 #define GRPC_APP_CALLBACK_EXEC_CTX_FLAG_IS_INTERNAL_THREAD 1
151 uintptr_t
flags() {
return flags_; }
195 now_is_valid_ =
true;
203 now_is_valid_ =
true;
220 gpr_tls_set(&exec_ctx_,
reinterpret_cast<intptr_t
>(exec_ctx));
233 static void operator delete(
void* ) { abort(); }
239 CombinerData combiner_data_ = {
nullptr,
nullptr};
244 bool now_is_valid_ =
false;
247 GPR_TLS_CLASS_DECL(exec_ctx_);
309 while (head_ !=
nullptr) {
312 if (f->internal_next ==
nullptr) {
315 (*f->functor_run)(f, f->internal_success);
317 gpr_tls_set(&callback_exec_ctx_,
reinterpret_cast<intptr_t
>(
nullptr));
333 gpr_tls_set(&callback_exec_ctx_,
reinterpret_cast<intptr_t
>(exec_ctx));
345 if (ctx->head_ ==
nullptr) {
346 ctx->head_ = functor;
348 if (ctx->tail_ !=
nullptr) {
351 ctx->tail_ = functor;
361 uintptr_t flags_{0u};
364 GPR_TLS_CLASS_DECL(callback_exec_ctx_);
Application-callback execution context.
Definition: exec_ctx.h:298
~ApplicationCallbackExecCtx()
Definition: exec_ctx.h:306
ApplicationCallbackExecCtx(uintptr_t fl)
Parameterised Constructor.
Definition: exec_ctx.h:304
static void Set(ApplicationCallbackExecCtx *exec_ctx, uintptr_t flags)
Definition: exec_ctx.h:327
ApplicationCallbackExecCtx()
Default Constructor.
Definition: exec_ctx.h:301
static void Enqueue(grpc_experimental_completion_queue_functor *functor, int is_success)
Definition: exec_ctx.h:337
static void GlobalShutdown(void)
Global shutdown for ApplicationCallbackExecCtx.
Definition: exec_ctx.h:358
static void GlobalInit(void)
Global initialization for ApplicationCallbackExecCtx.
Definition: exec_ctx.h:355
Definition: combiner.h:33
Definition: debug_location.h:31
Execution context.
Definition: exec_ctx.h:104
bool Flush()
Flush any work that has been enqueued onto this grpc_exec_ctx.
Definition: exec_ctx.cc:142
static ExecCtx * Get()
Gets pointer to current exec_ctx.
Definition: exec_ctx.h:215
ExecCtx(uintptr_t fl)
Parameterised Constructor.
Definition: exec_ctx.h:114
ExecCtx & operator=(const ExecCtx &)=delete
bool HasWork()
Checks if there is work to be done.
Definition: exec_ctx.h:154
static void RunList(const DebugLocation &location, grpc_closure_list *list)
Definition: exec_ctx.cc:198
ExecCtx(const ExecCtx &)=delete
Disallow copy and assignment operators.
static void Run(const DebugLocation &location, grpc_closure *closure, grpc_error *error)
Definition: exec_ctx.cc:172
void InvalidateNow()
Invalidates the stored time value.
Definition: exec_ctx.h:190
bool IsReadyToFinish()
Returns true if we'd like to leave this execution context as soon as possible: useful for deciding wh...
Definition: exec_ctx.h:169
virtual bool CheckReadyToFinish()
Check if ready to finish.
Definition: exec_ctx.h:230
grpc_millis Now()
Returns the stored current time relative to start if valid, otherwise refreshes the stored time,...
Definition: exec_ctx.cc:164
virtual ~ExecCtx()
Destructor.
Definition: exec_ctx.h:122
static void Set(ExecCtx *exec_ctx)
Definition: exec_ctx.h:219
static void GlobalInit(void)
Global initialization for ExecCtx.
Definition: exec_ctx.cc:131
uintptr_t flags()
Return flags.
Definition: exec_ctx.h:151
grpc_closure_list * closure_list()
Return pointer to grpc_closure_list.
Definition: exec_ctx.h:148
static void TestOnlyGlobalInit(gpr_timespec new_val)
Definition: exec_ctx.cc:126
static void GlobalShutdown(void)
Global shutdown for ExecCtx.
Definition: exec_ctx.h:212
CombinerData * combiner_data()
Only to be used by grpc-combiner code.
Definition: exec_ctx.h:145
unsigned starting_cpu() const
Definition: exec_ctx.h:135
void SetNowIomgrShutdown()
To be used only by shutdown code in iomgr.
Definition: exec_ctx.h:193
void TestOnlySetNow(grpc_millis new_val)
To be used only for testing.
Definition: exec_ctx.h:201
ExecCtx()
Default Constructor.
Definition: exec_ctx.h:108
static void DecExecCtxCount()
Definition: fork.h:57
static void IncExecCtxCount()
Definition: fork.h:50
bool grpc_closure_list_empty(grpc_closure_list closure_list)
return whether list is empty.
Definition: closure.h:223
#define GRPC_CLOSURE_LIST_INIT
Definition: closure.h:168
GPRAPI unsigned gpr_cpu_current_cpu(void)
Return the CPU on which the current thread is executing; N.B.
int64_t grpc_millis
Definition: exec_ctx.h:35
#define GRPC_EXEC_CTX_FLAG_IS_INTERNAL_THREAD
Definition: exec_ctx.h:52
#define GRPC_APP_CALLBACK_EXEC_CTX_FLAG_IS_INTERNAL_THREAD
Definition: exec_ctx.h:56
grpc_millis grpc_cycle_counter_to_millis_round_down(gpr_cycle_counter cycles)
Definition: exec_ctx.cc:111
#define GRPC_EXEC_CTX_FLAG_IS_FINISHED
Definition: exec_ctx.h:46
gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock)
Definition: exec_ctx.cc:83
grpc_millis grpc_cycle_counter_to_millis_round_up(gpr_cycle_counter cycles)
Definition: exec_ctx.cc:116
grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec)
Definition: exec_ctx.cc:101
struct grpc_combiner grpc_combiner
A combiner represents a list of work to be executed later.
Definition: exec_ctx.h:42
#define GRPC_MILLIS_INF_FUTURE
Definition: exec_ctx.h:37
grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec)
Definition: exec_ctx.cc:106
gpr_clock_type
The clocks we support.
Definition: gpr_types.h:31
#define GPR_DEBUG_ASSERT(x)
Definition: log.h:103
Round Robin Policy.
Definition: backend_metric.cc:24
Analogous to struct timespec.
Definition: gpr_types.h:47
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
Definition: exec_ctx.h:137
Combiner * last_combiner
Definition: exec_ctx.h:141
Combiner * active_combiner
Definition: exec_ctx.h:139
Definition: error_internal.h:39
EXPERIMENTAL: Specifies an interface class to be used as a tag for callback-based completion queues.
Definition: grpc_types.h:722
int internal_success
The following fields are not API.
Definition: grpc_types.h:734
struct grpc_experimental_completion_queue_functor * internal_next
Definition: grpc_types.h:735
#define gpr_tls_destroy(tls)
Definition: tls_gcc.h:46
#define gpr_tls_init(tls)
Definition: tls_gcc.h:43
#define gpr_tls_get(tls)
Definition: tls_gcc.h:50
intptr_t gpr_tls_set(struct gpr_pthread_thread_local *tls, intptr_t value)