File: GraphMonitor.mesa, Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by:
Sweetsun Chen, October 21, 1985 10:27:00 pm PDT
DIRECTORY
GraphPrivate USING [GraphHandle, GraphAtomProc, GraphPlaceProc, GraphProc],
GraphUtil USING [HandleNotNil],
Process USING [SecondsToTicks, SetTimeout];
GraphMonitor:
CEDAR
MONITOR
IMPORTS GraphUtil, Process
EXPORTS GraphPrivate = { OPEN GraphPrivate, GraphUtil;
timeOut: CONDITION;
Lock:
PUBLIC
ENTRY GraphProc = {
ENABLE UNWIND => NULL;
IF HandleNotNil[handle]
THEN {
WHILE handle.locked DO WAIT handle.unlocked; ENDLOOP;
handle.locked ← TRUE;
};
}; -- Lock
Unlock:
PUBLIC
ENTRY GraphProc = {
ENABLE UNWIND => NULL;
IF HandleNotNil[handle]
THEN {
handle.locked ← FALSE;
BROADCAST handle.unlocked;
};
}; -- Unlock
IsLocked:
PUBLIC
ENTRY
PROC [handle: GraphHandle ←
NIL]
RETURNS [
BOOL] = {
IF handle = NIL THEN RETURN[FALSE]
ELSE RETURN[handle.locked];
}; -- IsLocked
CallWithLock: PUBLIC PROC [handle: GraphPrivate.GraphHandle ← NIL, proc: GraphProc ← NIL] = {IF HandleNotNil[handle] THEN {Lock[handle]; proc[handle]; Unlock[handle]}}; -- CallWithLock
LockedPlaceProc:
PUBLIC
PROC [handle: GraphHandle ←
NIL, sx, sy:
INTEGER ← 0, proc: GraphPlaceProc ←
NIL] = {
lockedProc: GraphProc = {proc[handle, sx, sy]};
CallWithLock[handle, lockedProc];
}; -- LockedPlaceProc
LockedAtomProc:
PUBLIC
PROC [handle: GraphHandle ←
NIL, atom:
ATOM, proc: GraphAtomProc ←
NIL] = {
lockedProc: GraphProc = {proc[handle, atom]};
CallWithLock[handle, lockedProc];
}; -- LockedAtomProc
Wait:
PUBLIC
ENTRY
PROC = {
-- wait a second.
WAIT timeOut;
};
Init:
PROC =
TRUSTED {
Process.SetTimeout[@timeOut, Process.SecondsToTicks[1]];
};
Init[];
}.
CHANGE
LOG.
SChen, create at October 9, 1985 6:46:56 pm PDT.