Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

cstk.h

00001 //==========================================================================
00002 //   CSTK.H - header for
00003 //                             OMNeT++
00004 //            Discrete System Simulation in C++
00005 //
00006 //  Declaration:
00007 //    Stk : system stack for functions that use a lot of stack space
00008 //
00009 //  Macros:
00010 //    iSTK(), vSTK() : interface to Stk
00011 //
00012 //==========================================================================
00013 
00014 #ifndef __CSTK_H
00015 #define __CSTK_H
00016 
00017 #include "ccor.h"
00018 
00019 #if defined(__BORLANDC__) && __BCPLUSPLUS__<=0x310 && defined(__MSDOS__)
00020 //#  define USE_STK         /* enables stack switching with iSTK,vSTK */
00021 #endif
00022 
00023 /*------
00024  Windowing implementations of cEnvir generally require a lot of stack space.
00025  When a module function calls member functions of cEnvir, either for screen
00026  I/O or indirectly, through objectDeleted() or messageSent(), the stack
00027  space allocated for that simple module may not be enough for the call.
00028  In order to be able to keep the simple module stack sizes low, a two macros
00029  are provided. When these macros are placed at the entry points of the
00030  stack-intensive cEnvir member functions, the macros will switch to the main
00031  stack. This way the call will use the main stack, which is big enough and
00032  not the simple module's stack, which can be kept small.
00033     *** The mechanism is implemented only for MS-DOS/Borland C++ 3.1!
00034     *** Other platforms should use BIG module stacks!
00035 ------*/
00036 
00037 #if !defined( USE_STK )
00038 
00039 #define iSTK(x) long x;
00040 #define vSTK(x) long x;
00041 
00042 #else // if defined( USE_STK )
00043 
00044 
00045 //
00046 // internal class: enables stack switching with the iSTK and vSTK macros
00047 //
00048 // ** OBSOLETE **
00049 //
00050 struct Stk
00051 {
00052    static long _retval;
00053    static int _stkon;
00054    static int _exit;
00055    static JMP_BUF _jbuf;
00056    int _switched;
00057 
00058    Stk()  {_switched=0;}
00059    ~Stk() {if(_switched && _stkon) {_stkon=0;LONGJMP(_jbuf,1);}}
00060 
00061    long operator=(long l) {return _retval=l;}
00062 };
00063 
00064 extern "C" void use_stack(int *sp);
00065 
00066 //--- macro for use in functions returning char/int/long
00067 #define iSTK(x) Stk x; \
00068                 {if(!Stk::_stkon && simulation.runningModule()!=NULL) \
00069                   if(SETJMP(Stk::_jbuf)==0) { \
00070                      x._switched=1; \
00071                      Stk::_stkon=1; \
00072                      use_stack(cCoroutine::getMainSP()-32); \
00073                   } else \
00074                     return Stk::_retval;}
00075 
00076 //--- macro for use in void functions
00077 #define vSTK(x) Stk x; \
00078                 {if(!Stk::_stkon && simulation.runningModule()!=NULL) \
00079                   if(SETJMP(Stk::_jbuf)==0) { \
00080                      x._switched=1; \
00081                      Stk::_stkon=1; \
00082                      use_stack(cCoroutine::getMainSP()-32); \
00083                   } else \
00084                     return;}
00085 
00086 #endif  // defined( USE_STK )
00087 
00088 #endif
00089 

Generated at Sat May 4 15:45:48 2002 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001