home *** CD-ROM | disk | FTP | other *** search
- /* CoRtn.h */
-
- #ifndef __CoRtn_h
- #define __CoRtn_h
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
-
- typedef struct
- { int sl, fp, sp;
- } context;
-
- typedef void (*coproc)(void *handle);
-
- #define MAIN_CO ((coroutine *) -1)
-
- typedef struct coroutine
- { struct coroutine *next;
- context ctx;
- coproc comain;
- void *handle;
- unsigned active : 1;
- } coroutine;
-
- /* Create a new coroutine context. The coroutine is not started as a result
- * of this call. Returns a handle by which the coroutine may be refered to, or
- * NULL if the coroutine could not be created.
- */
-
- coroutine *create_co(coproc p, void *handle);
-
- /* Delete a coroutine, returning TRUE for success, FALSE for failure. The
- * coroutine may not be deleted if it is currently executing, or if it is
- * the main program (MAIN_CO).
- */
-
- int delete_co(coroutine *co);
-
- /* Return TRUE if the specified coroutine is active. A coroutine is active
- * from the time it is entered (goto_co() or start_co()) to the time it
- * returns normally (as opposed to exiting via goto_co()).
- */
-
- int monitor_co(coroutine *co);
-
- /* Force a coroutine to restart. Any existing context for the coroutine is
- * discarded. NOTE: Use this with care; any store which has been obtained
- * directly or indirectly from malloc() will not be freed.
- */
-
- int start_co(coroutine *co);
-
- /* Switch execution to the specified coroutine. If the coroutine is
- * currently inactive (i.e. created but not called, or returned normally) it
- * will be entered as a function, and passed the handle which was originally
- * passed to create_co(), otherwise a return from the most recent call to
- * goto_co() / start_co() will occur.
- */
-
- int goto_co(coroutine *co);
-
- #ifdef __cplusplus
- }
- #endif
-
-
- #endif
-