Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Static Private Member Functions | Private Attributes | List of all members
grpc_core::ExecCtx Class Reference

#include <exec_ctx.h>

Inheritance diagram for grpc_core::ExecCtx:
Inheritance graph
[legend]

Classes

struct  CombinerData
 

Public Member Functions

grpc_closure_listclosure_list ()
 
CombinerDatacombiner_data ()
 
 ExecCtx ()
 
 ExecCtx (const ExecCtx &)=delete
 
 ExecCtx (uintptr_t fl)
 
uintptr_t flags ()
 
bool Flush ()
 
bool HasWork ()
 
void InvalidateNow ()
 
bool IsReadyToFinish ()
 
Timestamp Now ()
 
ExecCtxoperator= (const ExecCtx &)=delete
 
void SetNowIomgrShutdown ()
 
unsigned starting_cpu ()
 
void TestOnlySetNow (Timestamp new_val)
 
virtual ~ExecCtx ()
 

Static Public Member Functions

static ExecCtxGet ()
 
static void Run (const DebugLocation &location, grpc_closure *closure, grpc_error_handle error)
 
static void RunList (const DebugLocation &location, grpc_closure_list *list)
 

Protected Member Functions

virtual bool CheckReadyToFinish ()
 

Static Protected Member Functions

static void operator delete (void *)
 

Static Private Member Functions

static GPR_THREAD_LOCAL (ExecCtx *) exec_ctx_
 
static void Set (ExecCtx *exec_ctx)
 

Private Attributes

grpc_closure_list closure_list_ = GRPC_CLOSURE_LIST_INIT
 
CombinerData combiner_data_ = {nullptr, nullptr}
 
uintptr_t flags_
 
ExecCtxlast_exec_ctx_ = Get()
 
Timestamp now_
 
bool now_is_valid_ = false
 
unsigned starting_cpu_ = std::numeric_limits<unsigned>::max()
 

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 :

ExecCtx exec_ctx;

Access the created ExecCtx instance using : 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.

Definition at line 97 of file exec_ctx.h.

Constructor & Destructor Documentation

◆ ExecCtx() [1/3]

grpc_core::ExecCtx::ExecCtx ( )
inline

Default Constructor

Definition at line 101 of file exec_ctx.h.

◆ ExecCtx() [2/3]

grpc_core::ExecCtx::ExecCtx ( uintptr_t  fl)
inlineexplicit

Parameterised Constructor

Definition at line 107 of file exec_ctx.h.

◆ ~ExecCtx()

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

Destructor

Definition at line 115 of file exec_ctx.h.

◆ 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.

Reimplemented in ExecCtxPluck, and ExecCtxNext.

Definition at line 214 of file exec_ctx.h.

◆ closure_list()

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

Return pointer to grpc_closure_list

Definition at line 146 of file exec_ctx.h.

◆ combiner_data()

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

Only to be used by grpc-combiner code

Definition at line 143 of file exec_ctx.h.

◆ flags()

uintptr_t grpc_core::ExecCtx::flags ( )
inline

Return flags

Definition at line 149 of file exec_ctx.h.

◆ 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.

Definition at line 69 of file exec_ctx.cc.

◆ Get()

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

Gets pointer to current exec_ctx.

Definition at line 205 of file exec_ctx.h.

◆ GPR_THREAD_LOCAL()

static grpc_core::ExecCtx::GPR_THREAD_LOCAL ( ExecCtx )
staticprivate

◆ HasWork()

bool grpc_core::ExecCtx::HasWork ( )
inline

Checks if there is work to be done

Definition at line 152 of file exec_ctx.h.

◆ InvalidateNow()

void grpc_core::ExecCtx::InvalidateNow ( )
inline

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

Definition at line 188 of file exec_ctx.h.

◆ 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.

Definition at line 167 of file exec_ctx.h.

◆ Now()

Timestamp 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.

Definition at line 90 of file exec_ctx.cc.

◆ operator delete()

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

Disallow delete on ExecCtx.

Definition at line 217 of file exec_ctx.h.

◆ operator=()

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

◆ Run()

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

Definition at line 98 of file exec_ctx.cc.

◆ RunList()

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

Definition at line 129 of file exec_ctx.cc.

◆ Set()

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

Set exec_ctx_ to exec_ctx.

Definition at line 221 of file exec_ctx.h.

◆ SetNowIomgrShutdown()

void grpc_core::ExecCtx::SetNowIomgrShutdown ( )
inline

To be used only by shutdown code in iomgr

Definition at line 191 of file exec_ctx.h.

◆ starting_cpu()

unsigned grpc_core::ExecCtx::starting_cpu ( )
inline

Definition at line 128 of file exec_ctx.h.

◆ TestOnlySetNow()

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

To be used only for testing. Sets the now value.

Definition at line 199 of file exec_ctx.h.

Member Data Documentation

◆ closure_list_

grpc_closure_list grpc_core::ExecCtx::closure_list_ = GRPC_CLOSURE_LIST_INIT
private

Definition at line 223 of file exec_ctx.h.

◆ combiner_data_

CombinerData grpc_core::ExecCtx::combiner_data_ = {nullptr, nullptr}
private

Definition at line 224 of file exec_ctx.h.

◆ flags_

uintptr_t grpc_core::ExecCtx::flags_
private

Definition at line 225 of file exec_ctx.h.

◆ last_exec_ctx_

ExecCtx* grpc_core::ExecCtx::last_exec_ctx_ = Get()
private

Definition at line 233 of file exec_ctx.h.

◆ now_

Timestamp grpc_core::ExecCtx::now_
private

Definition at line 230 of file exec_ctx.h.

◆ now_is_valid_

bool grpc_core::ExecCtx::now_is_valid_ = false
private

Definition at line 229 of file exec_ctx.h.

◆ starting_cpu_

unsigned grpc_core::ExecCtx::starting_cpu_ = std::numeric_limits<unsigned>::max()
private

Definition at line 227 of file exec_ctx.h.


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


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