19 #ifndef GRPC_CORE_LIB_IOMGR_EXEC_CTX_H
20 #define GRPC_CORE_LIB_IOMGR_EXEC_CTX_H
39 #define GRPC_MILLIS_INF_FUTURE INT64_MAX
40 #define GRPC_MILLIS_INF_PAST INT64_MIN
48 #define GRPC_EXEC_CTX_FLAG_IS_FINISHED 1
51 #define GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP 2
54 #define GRPC_EXEC_CTX_FLAG_IS_INTERNAL_THREAD 4
58 #define GRPC_APP_CALLBACK_EXEC_CTX_FLAG_IS_INTERNAL_THREAD 1
138 if (starting_cpu_ == std::numeric_limits<unsigned>::max()) {
141 return starting_cpu_;
158 uintptr_t
flags() {
return flags_; }
202 now_is_valid_ =
true;
210 now_is_valid_ =
true;
227 gpr_tls_set(&exec_ctx_,
reinterpret_cast<intptr_t
>(exec_ctx));
240 static void operator delete(
void* ) { abort(); }
246 CombinerData combiner_data_ = {
nullptr,
nullptr};
249 unsigned starting_cpu_ = std::numeric_limits<unsigned>::max();
251 bool now_is_valid_ =
false;
254 GPR_TLS_CLASS_DECL(exec_ctx_);
318 while (head_ !=
nullptr) {
321 if (f->internal_next ==
nullptr) {
324 (*f->functor_run)(f, f->internal_success);
326 gpr_tls_set(&callback_exec_ctx_,
reinterpret_cast<intptr_t
>(
nullptr));
336 uintptr_t
Flags() {
return flags_; }
344 if (
Get() ==
nullptr) {
348 gpr_tls_set(&callback_exec_ctx_,
reinterpret_cast<intptr_t
>(exec_ctx));
358 if (ctx->head_ ==
nullptr) {
359 ctx->head_ = functor;
361 if (ctx->tail_ !=
nullptr) {
364 ctx->tail_ = functor;
376 uintptr_t flags_{0u};
379 GPR_TLS_CLASS_DECL(callback_exec_ctx_);
Application-callback execution context.
Definition: exec_ctx.h:305
~ApplicationCallbackExecCtx()
Definition: exec_ctx.h:315
static void Enqueue(grpc_completion_queue_functor *functor, int is_success)
Definition: exec_ctx.h:352
static bool Available()
Definition: exec_ctx.h:373
ApplicationCallbackExecCtx(uintptr_t fl)
Parameterised Constructor.
Definition: exec_ctx.h:311
static void Set(ApplicationCallbackExecCtx *exec_ctx, uintptr_t flags)
Definition: exec_ctx.h:343
ApplicationCallbackExecCtx()
Default Constructor.
Definition: exec_ctx.h:308
uintptr_t Flags()
Definition: exec_ctx.h:336
static void GlobalShutdown(void)
Global shutdown for ApplicationCallbackExecCtx.
Definition: exec_ctx.h:371
static ApplicationCallbackExecCtx * Get()
Definition: exec_ctx.h:338
static void GlobalInit(void)
Global initialization for ApplicationCallbackExecCtx.
Definition: exec_ctx.h:368
Definition: combiner.h:33
Definition: debug_location.h:31
Execution context.
Definition: exec_ctx.h:106
bool Flush()
Flush any work that has been enqueued onto this grpc_exec_ctx.
Definition: exec_ctx.cc:154
static void Run(const DebugLocation &location, grpc_closure *closure, grpc_error_handle error)
Definition: exec_ctx.cc:184
static ExecCtx * Get()
Gets pointer to current exec_ctx.
Definition: exec_ctx.h:222
ExecCtx(uintptr_t fl)
Parameterised Constructor.
Definition: exec_ctx.h:116
ExecCtx & operator=(const ExecCtx &)=delete
bool HasWork()
Checks if there is work to be done.
Definition: exec_ctx.h:161
static void RunList(const DebugLocation &location, grpc_closure_list *list)
Definition: exec_ctx.cc:210
ExecCtx(const ExecCtx &)=delete
Disallow copy and assignment operators.
unsigned starting_cpu()
Definition: exec_ctx.h:137
void InvalidateNow()
Invalidates the stored time value.
Definition: exec_ctx.h:197
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:176
virtual bool CheckReadyToFinish()
Check if ready to finish.
Definition: exec_ctx.h:237
grpc_millis Now()
Returns the stored current time relative to start if valid, otherwise refreshes the stored time,...
Definition: exec_ctx.cc:176
virtual ~ExecCtx()
Destructor.
Definition: exec_ctx.h:124
static void Set(ExecCtx *exec_ctx)
Definition: exec_ctx.h:226
static void GlobalInit(void)
Global initialization for ExecCtx.
Definition: exec_ctx.cc:143
uintptr_t flags()
Return flags.
Definition: exec_ctx.h:158
grpc_closure_list * closure_list()
Return pointer to grpc_closure_list.
Definition: exec_ctx.h:155
static void TestOnlyGlobalInit(gpr_timespec new_val)
Definition: exec_ctx.cc:138
static void GlobalShutdown(void)
Global shutdown for ExecCtx.
Definition: exec_ctx.h:219
CombinerData * combiner_data()
Only to be used by grpc-combiner code.
Definition: exec_ctx.h:152
void SetNowIomgrShutdown()
To be used only by shutdown code in iomgr.
Definition: exec_ctx.h:200
void TestOnlySetNow(grpc_millis new_val)
To be used only for testing.
Definition: exec_ctx.h:208
ExecCtx()
Default Constructor.
Definition: exec_ctx.h:110
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:167
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:37
#define GRPC_EXEC_CTX_FLAG_IS_INTERNAL_THREAD
Definition: exec_ctx.h:54
#define GRPC_APP_CALLBACK_EXEC_CTX_FLAG_IS_INTERNAL_THREAD
Definition: exec_ctx.h:58
grpc_millis grpc_cycle_counter_to_millis_round_down(gpr_cycle_counter cycles)
Definition: exec_ctx.cc:123
#define GRPC_EXEC_CTX_FLAG_IS_FINISHED
Definition: exec_ctx.h:48
gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock)
Definition: exec_ctx.cc:95
grpc_millis grpc_cycle_counter_to_millis_round_up(gpr_cycle_counter cycles)
Definition: exec_ctx.cc:128
struct grpc_combiner grpc_combiner
A combiner represents a list of work to be executed later.
Definition: exec_ctx.h:44
#define GRPC_MILLIS_INF_FUTURE
Definition: exec_ctx.h:39
grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec ts)
Definition: exec_ctx.cc:118
grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec ts)
Definition: exec_ctx.cc:113
gpr_clock_type
The clocks we support.
Definition: gpr_types.h:31
#define GPR_DEBUG_ASSERT(x)
Definition: log.h:101
grpc_error_handle error
Definition: lame_client.cc:54
Round Robin Policy.
Definition: backend_metric.cc:26
grpc_closure closure
Definition: server.cc:460
Analogous to struct timespec.
Definition: gpr_types.h:47
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
Specifies an interface class to be used as a tag for callback-based completion queues.
Definition: grpc_types.h:757
int internal_success
The following fields are not API.
Definition: grpc_types.h:769
struct grpc_completion_queue_functor * internal_next
Definition: grpc_types.h:770
Definition: exec_ctx.h:144
Combiner * last_combiner
Definition: exec_ctx.h:148
Combiner * active_combiner
Definition: exec_ctx.h:146
Definition: error_internal.h:41
#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)