Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
grpc_core::ApplicationCallbackExecCtx Class Reference

#include <exec_ctx.h>

Public Member Functions

 ApplicationCallbackExecCtx ()
 
 ApplicationCallbackExecCtx (uintptr_t fl)
 
uintptr_t Flags ()
 
 ~ApplicationCallbackExecCtx ()
 

Static Public Member Functions

static bool Available ()
 
static void Enqueue (grpc_completion_queue_functor *functor, int is_success)
 
static ApplicationCallbackExecCtxGet ()
 
static void GlobalInit (void)
 
static void GlobalShutdown (void)
 
static void Set (ApplicationCallbackExecCtx *exec_ctx, uintptr_t flags)
 

Static Private Member Functions

static GPR_THREAD_LOCAL (ApplicationCallbackExecCtx *) callback_exec_ctx_
 

Private Attributes

uintptr_t flags_ {0u}
 
grpc_completion_queue_functorhead_ {nullptr}
 
grpc_completion_queue_functortail_ {nullptr}
 

Detailed Description

Application-callback execution context. A bag of data that collects information along a callstack. It is created on the stack at core entry points, and stored internally as a thread-local variable.

There are three key differences between this structure and ExecCtx:

  1. ApplicationCallbackExecCtx builds a list of application-level callbacks, but ExecCtx builds a list of internal callbacks to invoke.
  2. ApplicationCallbackExecCtx invokes its callbacks only at destruction; there is no explicit Flush method.
  3. If more than one ApplicationCallbackExecCtx is created on the thread's stack, only the one closest to the base of the stack is actually active and this is the only one that enqueues application callbacks. (Unlike ExecCtx, it is not feasible to prevent multiple of these on the stack since the executing application callback may itself enter core. However, the new one created will just pass callbacks through to the base one and those will not be executed until the return to the destructor of the base one, preventing unlimited stack growth.)

This structure exists because application callbacks may themselves cause a core re-entry (e.g., through a public API call) and if that call in turn causes another application-callback, there could be arbitrarily growing stacks of core re-entries. Instead, any application callbacks instead should not be invoked until other core work is done and other application callbacks have completed. To accomplish this, any application callback should be enqueued using ApplicationCallbackExecCtx::Enqueue .

CONVENTIONS:

Generally, core entry points that may trigger application-level callbacks will have the following declarations:

ApplicationCallbackExecCtx callback_exec_ctx; ExecCtx exec_ctx;

This ordering is important to make sure that the ApplicationCallbackExecCtx is destroyed after the ExecCtx (to prevent the re-entry problem described above, as well as making sure that ExecCtx core callbacks are invoked first)

Definition at line 283 of file exec_ctx.h.

Constructor & Destructor Documentation

◆ ApplicationCallbackExecCtx() [1/2]

grpc_core::ApplicationCallbackExecCtx::ApplicationCallbackExecCtx ( )
inline

Default Constructor

Definition at line 286 of file exec_ctx.h.

◆ ApplicationCallbackExecCtx() [2/2]

grpc_core::ApplicationCallbackExecCtx::ApplicationCallbackExecCtx ( uintptr_t  fl)
inlineexplicit

Parameterised Constructor

Definition at line 289 of file exec_ctx.h.

◆ ~ApplicationCallbackExecCtx()

grpc_core::ApplicationCallbackExecCtx::~ApplicationCallbackExecCtx ( )
inline

Definition at line 293 of file exec_ctx.h.

Member Function Documentation

◆ Available()

static bool grpc_core::ApplicationCallbackExecCtx::Available ( )
inlinestatic

Definition at line 347 of file exec_ctx.h.

◆ Enqueue()

static void grpc_core::ApplicationCallbackExecCtx::Enqueue ( grpc_completion_queue_functor functor,
int  is_success 
)
inlinestatic

Definition at line 326 of file exec_ctx.h.

◆ Flags()

uintptr_t grpc_core::ApplicationCallbackExecCtx::Flags ( )
inline

Definition at line 313 of file exec_ctx.h.

◆ Get()

static ApplicationCallbackExecCtx* grpc_core::ApplicationCallbackExecCtx::Get ( )
inlinestatic

Definition at line 315 of file exec_ctx.h.

◆ GlobalInit()

static void grpc_core::ApplicationCallbackExecCtx::GlobalInit ( void  )
inlinestatic

Global initialization for ApplicationCallbackExecCtx. Called by init.

Definition at line 342 of file exec_ctx.h.

◆ GlobalShutdown()

static void grpc_core::ApplicationCallbackExecCtx::GlobalShutdown ( void  )
inlinestatic

Global shutdown for ApplicationCallbackExecCtx. Called by init.

Definition at line 345 of file exec_ctx.h.

◆ GPR_THREAD_LOCAL()

static grpc_core::ApplicationCallbackExecCtx::GPR_THREAD_LOCAL ( ApplicationCallbackExecCtx )
staticprivate

◆ Set()

static void grpc_core::ApplicationCallbackExecCtx::Set ( ApplicationCallbackExecCtx exec_ctx,
uintptr_t  flags 
)
inlinestatic

Definition at line 317 of file exec_ctx.h.

Member Data Documentation

◆ flags_

uintptr_t grpc_core::ApplicationCallbackExecCtx::flags_ {0u}
private

Definition at line 350 of file exec_ctx.h.

◆ head_

grpc_completion_queue_functor* grpc_core::ApplicationCallbackExecCtx::head_ {nullptr}
private

Definition at line 351 of file exec_ctx.h.

◆ tail_

grpc_completion_queue_functor* grpc_core::ApplicationCallbackExecCtx::tail_ {nullptr}
private

Definition at line 352 of file exec_ctx.h.


The documentation for this class was generated from the following file:


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:35