- Main Page
- Modules
- Classes
- Files
- Directories
- Related Pages

- Class List
- Class Hierarchy
- Class Members

# cCoroutine Class Reference
[Internal classes]

`#include <ccoroutine.h>`

List of all members.

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

## Public Member Functions
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 Member Functions
static void | init (unsigned total_stack, unsigned main_stack)
static void | switchTo (cCoroutine *cor)
static void | switchToMain ()

## Constructor & Destructor Documentation

cCoroutine::cCoroutine | ( |  | ) |

| Constructor.

virtual cCoroutine::~cCoroutine | ( |  | ) | `[virtual]`

| Destructor.

## Member Function Documentation

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

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

virtual unsigned cCoroutine::stackSize | ( |  | ) | const`[virtual]`

| Returns the stack size of the coroutine.

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

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

static 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:

- ccoroutine.h