#include <CCoContext.h>
Collaboration diagram for AxPipe::CCoContext:
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. | |
CError * | m_pErr |
Point to an object where we can report an error. |
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.
|
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.
Definition at line 45 of file CCoContext.cpp. |
|
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. |
|
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.
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(). |
|
Initalize the error object pointer, the StartProc and the param.
Definition at line 55 of file CCoContext.cpp. |
|
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. |