Resource:
CEDAR
DEFINITIONS =
BEGIN
This interface is intended to provide more flexibility than MONITORs for managing resources that support only one client at a time (e.g. Compiler, Binder, DFFile software). "resource" is typically an ATOM; the implementations of Acquire and Release use =. Acquire will return success = FALSE either if waitForIt = FALSE and the resource is in use (i.e. previously "Acquire'd" but not yet released), or if waitForIt = TRUE and abortProc # NIL and a call on abortProc returned TRUE. If Acquire returns success = FALSE then ownedBy will identify the current owner.
Acquire:
PROC
[resource: REF ANY,
waitForIt: BOOL ← FALSE,
owner: Rope.ROPE ← NIL,
abortProc: AbortProc ←
NIL,
if non-NIL, abortProc[abortProcData] is called occasionally while Acquire is waiting
abortProcData: REF ANY ← NIL
]
RETURNS[success: BOOL, ownedBy: Rope.ROPE];
AbortProc: TYPE = PROC[data: REF ANY] RETURNS[abort: BOOL];
Release: PROC[resource: REF ANY] RETURNS[success: BOOL];
IsAvailable:
PROC[resource:
REF
ANY]
RETURNS[yes:
BOOL, owner: Rope.
ROPE];
IF IsAvailable returns yes = TRUE, then owner is valid.
BEWARE of races; caveat emptor
END.