Synchronizer.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Tim Diebert: April 27, 1987 2:58:12 pm PDT
DIRECTORY
Process USING [DisableAborts, DisableTimeout, EnableAborts, Milliseconds, MsecToTicks, SetTimeout];
Synchronizer: CEDAR DEFINITIONS
LOCKS sync USING sync: Synchronizer
IMPORTS Process = BEGIN
Constants:
maximumLapse: Process.Milliseconds = LAST[Process.Milliseconds];
TYPEs:
Synchronizer: TYPE = REF SynchronizerRep;
SynchronizerRep: TYPE = MONITORED RECORD [condition: CONDITION, count: CARDINAL];
INLINE ENTRY PROCEDUREs:
Initialize: ENTRY PROCEDURE [sync: Synchronizer,
enableAbort, enableTimeout: BOOLEAN, lapse: Process.Milliseconds ← maximumLapse] = TRUSTED INLINE BEGIN
ENABLE UNWIND => NULL;
IF enableAbort
THEN Process.EnableAborts[pCondition: @sync.condition]
ELSE Process.DisableAborts[pCondition: @sync.condition];
IF enableTimeout
THEN Process.SetTimeout[condition: @sync.condition, ticks: Process.MsecToTicks[lapse]]
ELSE Process.DisableTimeout[condition: @sync.condition];
sync.count ← 0;
END;
Broadcast: ENTRY PROCEDURE [sync: Synchronizer] = INLINE BEGIN
ENABLE UNWIND => NULL;
sync.count ← sync.count + 1;
BROADCAST sync.condition;
END;
ForceTimeout: ENTRY PROCEDURE [sync: Synchronizer] = INLINE BEGIN
ENABLE UNWIND => NULL;
BROADCAST sync.condition;
END;
Notify: ENTRY PROCEDURE [sync: Synchronizer] = INLINE BEGIN
ENABLE UNWIND => NULL;
sync.count ← sync.count + 1;
NOTIFY sync.condition;
END;
Wait: ENTRY PROCEDURE [sync: Synchronizer] RETURNS [timeout: BOOLEAN] = INLINE BEGIN
ENABLE UNWIND => NULL;
localCount: CARDINAL ← sync.count;
WAIT sync.condition;
RETURN[timeout: localCount = sync.count];
END;
END.