GRPC Core  18.0.0
Public Member Functions | Static Public Member Functions
grpc_core::ApplicationCallbackExecCtx Class Reference

Application-callback execution context. More...

#include <exec_ctx.h>

Public Member Functions

 ApplicationCallbackExecCtx ()
 Default Constructor. More...
 
 ApplicationCallbackExecCtx (uintptr_t fl)
 Parameterised Constructor. More...
 
 ~ApplicationCallbackExecCtx ()
 
uintptr_t Flags ()
 

Static Public Member Functions

static ApplicationCallbackExecCtxGet ()
 
static void Set (ApplicationCallbackExecCtx *exec_ctx, uintptr_t flags)
 
static void Enqueue (grpc_completion_queue_functor *functor, int is_success)
 
static void GlobalInit (void)
 Global initialization for ApplicationCallbackExecCtx. More...
 
static void GlobalShutdown (void)
 Global shutdown for ApplicationCallbackExecCtx. More...
 
static bool Available ()
 

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 grpc_core::ApplicationCallbackExecCtx::Enqueue .

CONVENTIONS:

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

grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::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)

Constructor & Destructor Documentation

◆ ApplicationCallbackExecCtx() [1/2]

grpc_core::ApplicationCallbackExecCtx::ApplicationCallbackExecCtx ( )
inline

Default Constructor.

◆ ApplicationCallbackExecCtx() [2/2]

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

Parameterised Constructor.

◆ ~ApplicationCallbackExecCtx()

grpc_core::ApplicationCallbackExecCtx::~ApplicationCallbackExecCtx ( )
inline

Member Function Documentation

◆ Available()

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

◆ Enqueue()

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

◆ Flags()

uintptr_t grpc_core::ApplicationCallbackExecCtx::Flags ( )
inline

◆ Get()

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

◆ GlobalInit()

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

Global initialization for ApplicationCallbackExecCtx.

Called by init.

◆ GlobalShutdown()

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

Global shutdown for ApplicationCallbackExecCtx.

Called by init.

◆ Set()

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

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