home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / program / code / andylib / h / CoRtn next >
Encoding:
Text File  |  1993-08-10  |  1.7 KB  |  70 lines

  1. /* CoRtn.h */
  2.  
  3. #ifndef __CoRtn_h
  4. #define __CoRtn_h
  5.  
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9.  
  10.  
  11. typedef struct
  12. {  int sl, fp, sp;
  13. } context;
  14.  
  15. typedef void (*coproc)(void *handle);
  16.  
  17. #define MAIN_CO ((coroutine *) -1)
  18.  
  19. typedef struct coroutine
  20. {  struct coroutine *next;
  21.    context ctx;
  22.    coproc comain;
  23.    void *handle;
  24.    unsigned active : 1;
  25. } coroutine;
  26.  
  27. /* Create a new coroutine context.  The coroutine is not started as a result
  28.  * of this call.  Returns a handle by which the coroutine may be refered to, or
  29.  * NULL if the coroutine could not be created.
  30.  */
  31.  
  32. coroutine *create_co(coproc p, void *handle);
  33.  
  34. /* Delete a coroutine, returning TRUE for success, FALSE for failure.  The
  35.  * coroutine may not be deleted if it is currently executing, or if it is
  36.  * the main program (MAIN_CO).
  37.  */
  38.  
  39. int delete_co(coroutine *co);
  40.  
  41. /* Return TRUE if the specified coroutine is active.  A coroutine is active
  42.  * from the time it is entered (goto_co() or start_co()) to the time it
  43.  * returns normally (as opposed to exiting via goto_co()).
  44.  */
  45.  
  46. int monitor_co(coroutine *co);
  47.  
  48. /* Force a coroutine to restart.  Any existing context for the coroutine is
  49.  * discarded.  NOTE: Use this with care; any store which has been obtained
  50.  * directly or indirectly from malloc() will not be freed.
  51.  */
  52.  
  53. int start_co(coroutine *co);
  54.  
  55. /* Switch execution to the specified coroutine.  If the coroutine is
  56.  * currently inactive (i.e. created but not called, or returned normally) it
  57.  * will be entered as a function, and passed the handle which was originally
  58.  * passed to create_co(), otherwise a return from the most recent call to
  59.  * goto_co() / start_co() will occur.
  60.  */
  61.  
  62. int goto_co(coroutine *co);
  63.  
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67.  
  68.  
  69. #endif
  70.