home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / CCL110JE.ZIP / COROUTIN.H < prev    next >
C/C++ Source or Header  |  1993-06-19  |  2KB  |  55 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //      COROUTINE.H: header file for DOS coroutine library.
  4. //      Copyright (c) J.English 1993.
  5. //      Author's address: je@unix.brighton.ac.uk
  6. //
  7. //      Permission is granted to use copy and distribute the
  8. //      information contained in this file provided that this
  9. //      copyright notice is retained intact and that any software
  10. //      or other document incorporating this file or parts thereof
  11. //      makes the source code for the library of which this file
  12. //      is a part freely available.
  13. //
  14. //--------------------------------------------------------------------------
  15. //
  16. //      Revision history:
  17. //      1.0     April 1993      Initial coding
  18. //      1.1     June 1993       Added wait, terminate; tidied private data
  19. //
  20. //--------------------------------------------------------------------------
  21.  
  22. #ifndef __COROUTINE_H
  23. #define __COROUTINE_H
  24.  
  25. //--------------------------------------------------------------------------
  26. //
  27. //      Class Coroutine: abstract DOS coroutine base class.
  28. //
  29. //      Note that you must derive a concrete class from this base class
  30. //      by supplying a main function containing the body of the task.
  31. //
  32. class Coroutine
  33. {
  34.     friend class CoroutineManager;
  35.     
  36.   public:
  37.     Coroutine (unsigned stacksize = 2048);  // constructor
  38.     virtual ~Coroutine ();                  // destructor
  39.  
  40.     int  run ();                            // start coroutine running
  41.     void terminate ();                      // terminate coroutine
  42.     void wait ();                           // wait for coroutine termination
  43.  
  44.     static void pause ();                   // schedule next coroutine
  45.  
  46.   protected:
  47.     virtual void main () = 0;               // main body of coroutine
  48.  
  49.   private:
  50.     CoroutineManager* const entry;
  51.     enum { CREATED, RUNNING, TERMINATED } state;
  52. };
  53.  
  54. #endif
  55.