-- FTPEvent.mesa - last edit:
-- MAS May 19, 1980  6:08 PM  
-- HGM September 30, 1980  5:45 PM  

-- Copyright  Xerox Corporation 1979, 1980

DIRECTORY
  FTPDefs,
  FTPPrivateDefs,
  Process USING [InitializeCondition, InitializeMonitor];

FTPEvent: MONITOR
  -- lock identification
  LOCKS event USING event: Event
  -- import list

  IMPORTS Process
  -- export list

  EXPORTS FTPPrivateDefs
  -- share list

  SHARES FTPDefs =
  BEGIN OPEN FTPDefs, FTPPrivateDefs;



  PrepareEvent: PUBLIC PROCEDURE [event: Event] =
    BEGIN
    -- prepare event object
    event.fact ← FALSE;
    -- initialize hint condition
    Process.InitializeCondition[@event.hint, LAST[CARDINAL]];
    -- initialize monitor lock
    Process.InitializeMonitor[@event.LOCK];
    END;

  PostEvent: PUBLIC ENTRY PROCEDURE [event: Event] =
    BEGIN
    ENABLE UNWIND => NULL;
    -- post event
    event.fact ← TRUE;
    BROADCAST event.hint;
    END;

  AwaitEvent: PUBLIC ENTRY PROCEDURE [event: Event] =
    BEGIN
    ENABLE UNWIND => NULL;
    -- Note:  Waits indefinitely.
    -- await event
    UNTIL event.fact DO WAIT event.hint; ENDLOOP;
    event.fact ← FALSE;
    END;

  END. -- FTPEvent