modula-2 home

  Home  
  Tutorial  
  Win32 API  
  Reference  
  Projects  
 

 
DEFINITION MODULE COROUTINES;
 
(* Facilities for coroutines and the handling of interrupts *)
 
IMPORT SYSTEM;
 
TYPE
  COROUTINE; (* Values of this type are created dynamically by NEWCOROUTINE 
                and identify the coroutine in subsequent operations *)
  INTERRUPTSOURCE = <implementation-defined> ;
 
PROCEDURE NEWCOROUTINE (procBody: PROC; workspace: SYSTEM.ADDRESS; size: CARDINAL;
                        VAR cr: COROUTINE[; initProtection: PROTECTION]);
  (* Creates a new coroutine whose body is given by procBody, and returns the identity
     of the coroutine in cr.  workspace is a pointer to the work space allocated to
     the coroutine; size specifies the size of this workspace in terms of SYSTEM.LOC.
     initProtection is an optional parameter that specifies the initial protection
     level of the coroutine.
  *)
 
PROCEDURE TRANSFER (VAR from: COROUTINE; to: COROUTINE);
  (* Returns the identity of the calling coroutine in from, and transfers control to
     the coroutine specified by to.
  *)
 
PROCEDURE IOTRANSFER (VAR from: COROUTINE; to: COROUTINE);
  (* Returns the identity of the calling coroutine in from and transfers control to
     the coroutine specified by to.  On occurrence of an interrupt, associated with the
     caller, control is transferred back to the caller, and the identity of the
     interrupted coroutine is returned in from.  The calling coroutine must be
     associated with a source of interrupts.
  *)
     
PROCEDURE ATTACH (source: INTERRUPTSOURCE);
  (* Associates the specified source of interrupts with the calling coroutine. *)
 
PROCEDURE DETACH (source: INTERRUPTSOURCE);
  (* Dissociates the specified source of interrupts from the calling coroutine. *)
 
PROCEDURE IsATTACHED (source: INTERRUPTSOURCE): BOOLEAN;
  (* Returns TRUE if and only if the specified source of interrupts is currently
     associated with a coroutine; otherwise returns FALSE.
  *)
 
PROCEDURE HANDLER (source: INTERRUPTSOURCE): COROUTINE;
  (* Returns the coroutine, if any, that is associated with the source of interrupts.
     The result is undefined if IsATTACHED(source) = FALSE.
  *)
 
PROCEDURE CURRENT (): COROUTINE;
  (* Returns the identity of the calling coroutine. *)
 
PROCEDURE LISTEN (p: PROTECTION);
  (* Momentarily changes the protection of the calling coroutine to p. *)
 
PROCEDURE PROT (): PROTECTION;
  (* Returns the protection of the calling coroutine. *)
 
END COROUTINES.