IExecutionContext Structure
An interface to an execution context which can run on a given virtual processor and be cooperatively context switched.
struct IExecutionContext;
Name | Description |
---|---|
IExecutionContext::Dispatch | The method that is called when a thread proxy starts executing a particular execution context. This should be the main worker routine for your scheduler. |
IExecutionContext::GetId | Returns a unique identifier for the execution context. |
IExecutionContext::GetProxy | Returns an interface to the thread proxy that is executing this context. |
IExecutionContext::GetScheduler | Returns an interface to the scheduler this execution context belongs to. |
IExecutionContext::SetProxy | Associates a thread proxy with this execution context. The associated thread proxy invokes this method right before it starts executing the context's Dispatch method. |
If you are implementing a custom scheduler that interfaces with the Concurrency Runtime's Resource Manager, you will need to implement the IExecutionContext
interface. The threads created by the Resource Manager perform work on behalf of your scheduler by executing the IExecutionContext::Dispatch
method.
IExecutionContext
Header: concrtrm.h
Namespace: concurrency
The method that is called when a thread proxy starts executing a particular execution context. This should be the main worker routine for your scheduler.
virtual void Dispatch(_Inout_ DispatchState* pDispatchState) = 0;
pDispatchState
A pointer to the state under which this execution context is being dispatched. For more information on dispatch state, see DispatchState.
Returns a unique identifier for the execution context.
virtual unsigned int GetId() const = 0;
A unique integer identifier.
You should use the method GetExecutionContextId
to obtain a unique identifier for the object that implements the IExecutionContext
interface, before you use the interface as a parameter to methods supplied by the Resource Manager. You are expected to return the same identifier when the GetId
function is invoked.
An identifier obtained from a different source could result in undefined behavior.
Returns an interface to the thread proxy that is executing this context.
virtual IThreadProxy* GetProxy() = 0;
An IThreadProxy
interface. If the execution context's thread proxy has not been initialized with a call to SetProxy
, the function must return NULL
.
The Resource Manager will invoke the SetProxy
method on an execution context, with an IThreadProxy
interface as a parameter, prior to entering the Dispatch
method on the on the context. You are expected to store this argument and return it on calls to GetProxy()
.
Returns an interface to the scheduler this execution context belongs to.
virtual IScheduler* GetScheduler() = 0;
An IScheduler
interface.
You are required to initialize the execution context with a valid IScheduler
interface before you use it as a parameter to methods supplied by the Resource Manager.
Associates a thread proxy with this execution context. The associated thread proxy invokes this method right before it starts executing the context's Dispatch
method.
virtual void SetProxy(_Inout_ IThreadProxy* pThreadProxy) = 0;
pThreadProxy
An interface to the thread proxy that is about to enter the Dispatch
method on this execution context.
You are expected to save the parameter pThreadProxy
and return it on a call to the GetProxy
method. The Resource Manager guarantees that the thread proxy associated with the execution context will not change while the thread proxy is executing the Dispatch
method.
concurrency Namespace
IScheduler Structure
IThreadProxy Structure