Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

AxPipe::CCoContext Class Reference

Encapsulate a co-routine context. More...

#include <CCoContext.h>

Collaboration diagram for AxPipe::CCoContext:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 CCoContext (CError *pErr=NULL, void(*pfStart)(void *)=NULL, void *pvParam=NULL)
 Create a new co-routine context.

void Init (CError *pErr, void(*pfStart)(void *), void *pvParam)
 Initalize the error object pointer, the StartProc and the param.

 ~CCoContext ()
 Stop this context.

bool Go ()
 Switch to this objects coroutine context. If it's the first call to an instance of the current context, then initialize the object to the current context instead. If it has a StartProc and it's the first call, then we start that, otherwise we just switch back to that co-routines context.

void Stop ()
 Stop and delete a co-routine context state.


Static Public Member Functions

VOID CALLBACK Start (PVOID lpParam)
 Helper for the CreateFiber call, needs a static callback, this is it.


Private Attributes

DWORD m_dwThreadId
 The thread we started the fiber in.

LPVOID m_pFiber
 This objects co-routine state.

void(* m_pfStart )(void *)
 Pointer to a StartProc.

void * m_pvParam
 The parameter sent to the StartProc.

CErrorm_pErr
 Point to an object where we can report an error.


Detailed Description

Encapsulate a co-routine context.

A co-routine is a context that executes along with other co-routines in the same process and thread, but with it's own stack, registers and program counter - sort of a very light weight thread, but with no independent scheduling, and by definition no concurrent or parallell execution.

In Windows Win32, this concept is called a 'fiber'. A CCoContext can be initalized to represent the already executing current context, or to create a new execution context. In most cases you first want to make a context represent the current context, then create a new context, that can then switch back to the original and then back again as needed.

The constructors may be called in any context. No creation or switching of contexts are done there.

Each CCoContext object thus represents one co-routine context in a thread.

Definition at line 59 of file CCoContext.h.


Constructor & Destructor Documentation

AxPipe::CCoContext::CCoContext CError pErr = NULL,
void(*  pfStart)(void *) = NULL,
void *  pvParam = NULL
 

Create a new co-routine context.

Construct a new context or, with a StartProc and a parameter to send it, or if no pfStart is provided, the currently executing context will be initalized to be the co-routine context. In either case it won't actually start at StartProc until Go() is called.

Parameters:
pErr Pointer to an CError derived object where we can send errors.
pfStart Pointer to a StartProc routine.
pvParam An opaque argument to StartProc, probably a 'this' pointer.

Definition at line 45 of file CCoContext.cpp.

AxPipe::CCoContext::~CCoContext  ) 
 

Stop this context.

Don't destruct this object from it's own context. If you do, and it's not the original context, it's an error. If it is the original context, nothing happens and the original thread must exit and clean up all by itself.

Definition at line 66 of file CCoContext.cpp.


Member Function Documentation

bool AxPipe::CCoContext::Go  ) 
 

Switch to this objects coroutine context. If it's the first call to an instance of the current context, then initialize the object to the current context instead. If it has a StartProc and it's the first call, then we start that, otherwise we just switch back to that co-routines context.

From the point of view of the caller of Go(), it'll look like any procedure call, Go() will execute and then return to the caller, but not when it executes 'return', but when that code executes a Go() to the co-routine context of the caller.

Returns:
true if we successfully switched and got back.

Definition at line 88 of file CCoContext.cpp.

References _T, ASSCHK, AxPipe::dwTlsIndex, AxPipe::ERROR_CODE_INTERNAL, m_dwThreadId, m_pErr, m_pFiber, m_pfStart, AxPipe::CError::SetError(), and Start().

Referenced by AxPipe::CFilter::CoStartFilter(), AxPipe::CFilterByte::GetNextSeg(), AxPipe::CFilter::Out(), AxPipe::CFilter::OutOpen(), and AxPipe::CFilter::Read().

void AxPipe::CCoContext::Init CError pErr,
void(*  pfStart)(void *),
void *  pvParam
 

Initalize the error object pointer, the StartProc and the param.

Parameters:
pErr Pointer to an CError derived object where we can send errors.
pfStart Pointer to a StartProc routine.
pvParam An opaque argument to StartProc, probably a 'this' pointer.

Definition at line 55 of file CCoContext.cpp.

References m_pErr, m_pfStart, and m_pvParam.

void AxPipe::CCoContext::Stop  ) 
 

Stop and delete a co-routine context state.

If we have a fiber context, and it was not made from the then current context, and it's not ourselves that are running, we delete the fiber.

(Otherwise, it must be the thread's responsibility to clean up and delete the initial fiber of a thread. This will happen automatically when the thread exits.)

Definition at line 143 of file CCoContext.cpp.

References _T, ASSCHK, m_pFiber, and m_pfStart.


The documentation for this class was generated from the following files:
Generated on Mon Feb 2 13:19:21 2004 for AxPipe by doxygen 1.3.5