MODULE Example7;
IMPORT Objects;
TYPE
RecursiveLock* = OBJECT
VAR lockedBy: ANY; level: LONGINT;
PROCEDURE Acquire*;
VAR me: ANY;
BEGIN {EXCLUSIVE}
me := Objects.ActiveObject();
IF lockedBy = me THEN
ASSERT(level # -1);
INC(level)
ELSE
AWAIT(lockedBy = NIL);
lockedBy := me; level := 1
END
END Acquire;
PROCEDURE Release*;
BEGIN {EXCLUSIVE}
ASSERT(lockedBy = Objects.ActiveObject());
DEC(level);
IF level = 0 THEN lockedBy := NIL END
END Release;
PROCEDURE &Init*;
BEGIN
lockedBy := NIL; level := 0
END Init;
END RecursiveLock;
END Example7.