Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

ccoroutine.h

00001 //==========================================================================
00002 //   CCOROUTINE.H  -  header for
00003 //                             OMNeT++
00004 //            Discrete System Simulation in C++
00005 //
00006 //  Declarations:
00007 //    class cCoroutine: coroutines
00008 //
00009 //==========================================================================
00010 
00011 /*--------------------------------------------------------------*
00012   Copyright (C) 1992-2003 Andras Varga
00013 
00014   This file is distributed WITHOUT ANY WARRANTY. See the file
00015   `license' for details on this and other legal matters.
00016 *--------------------------------------------------------------*/
00017 
00018 #ifndef __CCOROUTINE_H
00019 #define __CCOROUTINE_H
00020 
00021 // select coroutine library
00022 #ifdef _WIN32
00023 #define USE_WIN32_FIBERS
00024 #else
00025 #define USE_PORTABLE_COROUTINES
00026 #endif
00027 
00028 #include "defs.h"
00029 
00030 
00031 #ifdef USE_WIN32_FIBERS
00032 // Fiber API is not accessible in MSVC6.0 without a hack (next 3 lines):
00033 #if _MSC_VER==1200
00034 #define _WIN32_WINNT 0x0400 
00035 #endif 
00036 #include <windows.h>
00037 // their min() and max() macros interfere with us
00038 #undef min
00039 #undef max
00040 #endif
00041 
00042 #ifdef USE_PORTABLE_COROUTINES
00043 struct _Task;
00044 #endif
00045 
00046 
00052 typedef void (*CoroutineFnp)( void * );
00053 
00054 //--------------------------------------------------------------------------
00055 
00074 class SIM_API cCoroutine
00075 {
00076   protected:
00077 #ifdef USE_WIN32_FIBERS
00078     LPVOID lpFiber;
00079     static LPVOID lpMainFiber;
00080     unsigned stacksize;
00081 #endif
00082 #ifdef USE_PORTABLE_COROUTINES
00083     _Task *task;
00084 #endif
00085 
00086   public:
00089 
00094     static void init(unsigned total_stack, unsigned main_stack);
00095 
00101     static void switchTo(cCoroutine *cor);
00102 
00106     static void switchToMain();
00108 
00111 
00117     bool setup(CoroutineFnp fnp, void *arg, unsigned stack_size);
00118 
00122     cCoroutine();
00123 
00127     virtual ~cCoroutine();
00129 
00132 
00147     virtual bool stackOverflow() const;
00148 
00152     virtual unsigned stackSize() const;
00153 
00162     virtual unsigned stackUsage() const;
00164 };
00165 
00166 #endif
00167 
00168 

Generated at Mon Jun 16 23:37:31 2003 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001