ccoroutine.h

00001 //==========================================================================
00002 //   CCOROUTINE.H  -  header for
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //  Declarations:
00007 //    class cCoroutine: coroutines
00008 //
00009 //==========================================================================
00010 
00011 /*--------------------------------------------------------------*
00012   Copyright (C) 1992-2005 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 #define WIN32_LEAN_AND_MEAN
00037 #include <windows.h>
00038 // their min() and max() macros interfere with us
00039 #undef min
00040 #undef max
00041 #endif
00042 
00043 #ifdef USE_PORTABLE_COROUTINES
00044 struct _Task;
00045 #endif
00046 
00047 
00053 typedef void (*CoroutineFnp)( void * );
00054 
00055 //--------------------------------------------------------------------------
00056 
00075 class SIM_API cCoroutine
00076 {
00077   protected:
00078 #ifdef USE_WIN32_FIBERS
00079     LPVOID lpFiber;
00080     static LPVOID lpMainFiber;
00081     unsigned stacksize;
00082 #endif
00083 #ifdef USE_PORTABLE_COROUTINES
00084     _Task *task;
00085 #endif
00086 
00087   public:
00090 
00095     static void init(unsigned total_stack, unsigned main_stack);
00096 
00102     static void switchTo(cCoroutine *cor);
00103 
00107     static void switchToMain();
00109 
00112 
00118     bool setup(CoroutineFnp fnp, void *arg, unsigned stack_size);
00119 
00123     cCoroutine();
00124 
00128     virtual ~cCoroutine();
00130 
00133 
00148     virtual bool stackOverflow() const;
00149 
00153     virtual unsigned stackSize() const;
00154 
00163     virtual unsigned stackUsage() const;
00165 };
00166 
00167 #endif
00168 
00169 

Generated on Sat Oct 21 17:47:55 2006 for OMNeT++/OMNEST Simulation Library by  doxygen 1.4.6