Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

cCoroutine Class Reference

#include <ccoroutine.h>

List of all members.

Public Methods

bool setup (CoroutineFnp fnp, void *arg, unsigned stack_size)
 cCoroutine ()
virtual ~cCoroutine ()
virtual bool stackOverflow () const
virtual unsigned stackSize () const
virtual unsigned stackUsage () const

Static Public Methods

void init (unsigned total_stack, unsigned main_stack)
void switchTo (cCoroutine *cor)
void switchToMain ()


Detailed Description

Low-level coroutine library. Coroutines are used by cSimpleModule.

cCoroutine has platform-dependent implementation:

On Windows, it uses the Win32 Fiber API.

On other platforms, the implementation a portable coroutine library, first described by Stig Kofoed ("Portable coroutines", see the Manual for a better reference). It creates all coroutine stacks within the main stack, and uses setjmp()/longjmp() for context switching. This implies that the maximum stack space allowed by the operating system for the OMNeT++ process must be sufficiently high (several, maybe several hundred megabytes), otherwise a segmentation fault will occur.


Constructor & Destructor Documentation

cCoroutine::cCoroutine ( )
 

Constructor.

cCoroutine::~cCoroutine ( ) [virtual]
 

Destructor.


Member Function Documentation

void cCoroutine::init ( unsigned total_stack,
unsigned main_stack ) [static]
 

Initializes the coroutine library. This function has to be called exactly once in a program, possibly at the top of main().

bool cCoroutine::setup ( CoroutineFnp fnp,
void * arg,
unsigned stack_size )
 

Sets up a coroutine. The arguments are the function that should be run in the coroutine, a pointer that is passed to the coroutine function, and the stack size.

bool cCoroutine::stackOverflow ( ) const [virtual]
 

Returns true if there was a stack overflow during execution of the coroutine.

Windows/Fiber API: Not implemented: always returns false.

Portable coroutines: it checks the intactness of a predefined byte pattern (0xdeadbeef) at the stack boundary, and report stack overflow if it was overwritten. The mechanism usually works fine, but occasionally it can be fooled by large uninitialized local variables (e.g. char buffer[256]): if the byte pattern happens to fall in the middle of such a local variable, it may be preserved intact and stack violation is not detected.

unsigned cCoroutine::stackSize ( ) const [virtual]
 

Returns the stack size of the coroutine.

unsigned cCoroutine::stackUsage ( ) const [virtual]
 

Returns the amount of stack actually used by the coroutine.

Windows/Fiber API: Not implemented, always returns 0.

Portable coroutines: It works by checking the intactness of predefined byte patterns (0xdeadbeef) placed in the stack.

void cCoroutine::switchTo ( cCoroutine * cor ) [static]
 

Switch to another coroutine. The execution of the current coroutine is suspended and the other coroutine is resumed from the point it last left off.

void cCoroutine::switchToMain ( ) [static]
 

Switch to the main coroutine (the one main() runs in).


The documentation for this class was generated from the following file:
Generated at Mon Jun 16 23:37:32 2003 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001