GRPC C++  1.26.0
Data Structures | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions
grpc_core::ExecCtx Class Reference

Execution context. More...

#include <exec_ctx.h>

Data Structures

struct  CombinerData
 

Public Member Functions

 ExecCtx ()
 Default Constructor. More...
 
 ExecCtx (uintptr_t fl)
 Parameterised Constructor. More...
 
virtual ~ExecCtx ()
 Destructor. More...
 
 ExecCtx (const ExecCtx &)=delete
 Disallow copy and assignment operators. More...
 
ExecCtxoperator= (const ExecCtx &)=delete
 
unsigned starting_cpu () const
 
CombinerDatacombiner_data ()
 Only to be used by grpc-combiner code. More...
 
grpc_closure_listclosure_list ()
 Return pointer to grpc_closure_list. More...
 
uintptr_t flags ()
 Return flags. More...
 
bool HasWork ()
 Checks if there is work to be done. More...
 
bool Flush ()
 Flush any work that has been enqueued onto this grpc_exec_ctx. More...
 
bool IsReadyToFinish ()
 Returns true if we'd like to leave this execution context as soon as possible: useful for deciding whether to do something more or not depending on outside context. More...
 
grpc_millis Now ()
 Returns the stored current time relative to start if valid, otherwise refreshes the stored time, sets it valid and returns the new value. More...
 
void InvalidateNow ()
 Invalidates the stored time value. More...
 
void SetNowIomgrShutdown ()
 To be used only by shutdown code in iomgr. More...
 
void TestOnlySetNow (grpc_millis new_val)
 To be used only for testing. More...
 

Static Public Member Functions

static void TestOnlyGlobalInit (gpr_timespec new_val)
 
static void GlobalInit (void)
 Global initialization for ExecCtx. More...
 
static void GlobalShutdown (void)
 Global shutdown for ExecCtx. More...
 
static ExecCtxGet ()
 Gets pointer to current exec_ctx. More...
 
static void Set (ExecCtx *exec_ctx)
 
static void Run (const DebugLocation &location, grpc_closure *closure, grpc_error *error)
 
static void RunList (const DebugLocation &location, grpc_closure_list *list)
 

Protected Member Functions

virtual bool CheckReadyToFinish ()
 Check if ready to finish. More...
 

Static Protected Member Functions

static void operator delete (void *)
 Disallow delete on ExecCtx. More...
 

Detailed Description

Execution context.

A bag of data that collects information along a callstack. It is created on the stack at core entry points (public API or iomgr), and stored internally as a thread-local variable.

Generally, to create an exec_ctx instance, add the following line at the top of the public API entry point or at the start of a thread's work function :

grpc_core::ExecCtx exec_ctx;

Access the created ExecCtx instance using : grpc_core::ExecCtx::Get()

Specific responsibilities (this may grow in the future):

CONVENTIONS:

TODO(yashykt): Only allow one "active" ExecCtx on a thread at the same time. Stage 1: If a new one is created on the stack, it should just pass-through to the underlying ExecCtx deeper in the thread's stack. Stage 2: Assert if a 2nd one is ever created on the stack since that implies a core re-entry outside of application callbacks.

Constructor & Destructor Documentation

◆ ExecCtx() [1/3]

grpc_core::ExecCtx::ExecCtx ( )
inline

Default Constructor.

◆ ExecCtx() [2/3]

grpc_core::ExecCtx::ExecCtx ( uintptr_t  fl)
inline

Parameterised Constructor.

◆ ~ExecCtx()

virtual grpc_core::ExecCtx::~ExecCtx ( )
inlinevirtual

Destructor.

◆ ExecCtx() [3/3]

grpc_core::ExecCtx::ExecCtx ( const ExecCtx )
delete

Disallow copy and assignment operators.

Member Function Documentation

◆ CheckReadyToFinish()

virtual bool grpc_core::ExecCtx::CheckReadyToFinish ( )
inlineprotectedvirtual

Check if ready to finish.

◆ closure_list()

grpc_closure_list* grpc_core::ExecCtx::closure_list ( )
inline

Return pointer to grpc_closure_list.

◆ combiner_data()

CombinerData* grpc_core::ExecCtx::combiner_data ( )
inline

Only to be used by grpc-combiner code.

◆ flags()

uintptr_t grpc_core::ExecCtx::flags ( )
inline

Return flags.

◆ Flush()

bool grpc_core::ExecCtx::Flush ( )

Flush any work that has been enqueued onto this grpc_exec_ctx.

Caller must guarantee that no interfering locks are held. Returns true if work was performed, false otherwise.

◆ Get()

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

Gets pointer to current exec_ctx.

◆ GlobalInit()

static void grpc_core::ExecCtx::GlobalInit ( void  )
static

Global initialization for ExecCtx.

Called by iomgr.

◆ GlobalShutdown()

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

Global shutdown for ExecCtx.

Called by iomgr.

◆ HasWork()

bool grpc_core::ExecCtx::HasWork ( )
inline

Checks if there is work to be done.

◆ InvalidateNow()

void grpc_core::ExecCtx::InvalidateNow ( )
inline

Invalidates the stored time value.

A new time value will be set on calling Now().

◆ IsReadyToFinish()

bool grpc_core::ExecCtx::IsReadyToFinish ( )
inline

Returns true if we'd like to leave this execution context as soon as possible: useful for deciding whether to do something more or not depending on outside context.

◆ Now()

grpc_millis grpc_core::ExecCtx::Now ( )

Returns the stored current time relative to start if valid, otherwise refreshes the stored time, sets it valid and returns the new value.

◆ operator delete()

static void grpc_core::ExecCtx::operator delete ( void *  )
inlinestaticprotected

Disallow delete on ExecCtx.

◆ operator=()

ExecCtx& grpc_core::ExecCtx::operator= ( const ExecCtx )
delete

◆ Run()

static void grpc_core::ExecCtx::Run ( const DebugLocation location,
grpc_closure closure,
grpc_error error 
)
static

◆ RunList()

static void grpc_core::ExecCtx::RunList ( const DebugLocation location,
grpc_closure_list list 
)
static

◆ Set()

static void grpc_core::ExecCtx::Set ( ExecCtx exec_ctx)
inlinestatic

◆ SetNowIomgrShutdown()

void grpc_core::ExecCtx::SetNowIomgrShutdown ( )
inline

To be used only by shutdown code in iomgr.

◆ starting_cpu()

unsigned grpc_core::ExecCtx::starting_cpu ( ) const
inline

◆ TestOnlyGlobalInit()

static void grpc_core::ExecCtx::TestOnlyGlobalInit ( gpr_timespec  new_val)
static

◆ TestOnlySetNow()

void grpc_core::ExecCtx::TestOnlySetNow ( grpc_millis  new_val)
inline

To be used only for testing.

Sets the now value.


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