DIRECTORY Rope USING [ROPE], TEditDocument USING [TEditDocumentData], TextNode USING [Ref]; TEditLocks: CEDAR DEFINITIONS = BEGIN LockRef: TYPE = REF LockRecord; LockRecord: TYPE = MONITORED RECORD [ waitingForWrite: INTEGER _ 0, -- number of processes waiting for write access to this document count, maxCount: [0..255] _ 0, -- number of times have entered this lock process: PROCESS _ NIL, -- the unique process which has write access to this document whoLast, whoFirst: Rope.ROPE, -- provided by the lockers unlocked: CONDITION -- raised when the lock is freed ]; Access: TYPE = { read, write }; Lock: PROC [doc: TextNode.Ref, who: Rope.ROPE, access: Access _ write] RETURNS [LockRef]; LockBoth: PROC [doc1, doc2: TextNode.Ref, who: Rope.ROPE, access1, access2: Access _ write] RETURNS [lock1, lock2: LockRef]; LockOrder: PROC [doc1, doc2: TextNode.Ref] RETURNS [BOOL] = INLINE { RETURN [LOOPHOLE[doc1, INT] <= LOOPHOLE[doc2, INT]] }; Unlock: PROC [doc: TextNode.Ref]; LockDocAndTdd: PROC [tdd: TEditDocument.TEditDocumentData, who: Rope.ROPE, access: Access _ write, interrupt, defer: BOOL _ FALSE] RETURNS [LockRef]; UnlockDocAndTdd: PROC [tdd: TEditDocument.TEditDocumentData]; WaitingForWrite: PROC [lock: LockRef] RETURNS [BOOL] = INLINE { RETURN [lock.waitingForWrite > 0] }; END. ’TEditLocks.mesa; Edited by Paxton on October 20, 1982 7:35 am Last Edited by: Maxwell, January 6, 1983 10:32 am Declarations Procedures Can only lock a document if (1) it is unlocked, or (2) current process has a write lock on it already If neither holds, then waits until it can lock it. Note that cannot convert a read lock into a write lock. (Implementation limitation.) Many processes can have read locks; only one can have a write lock. When a write lock is released, all viewers for the document have their tdd.dirty bit set true. Like two calls on Lock, but orders the calls according to LockOrder. Returns true if ok to lock doc1 before doc2. Reduces the lock count for the document. access is for locking the document; interrupt and defer are for locking the tdd if defer and don't get the tdd lock, then returns nil. Returns true iff some process is waiting to get a write lock for the document. ʘšœ=™=JšÏk1™1—š ˜ Jšœœœ˜Jšœœ˜(Jšœ œ˜J˜—šœ œ˜%J˜—™ J˜Jšœ œœ ˜šœ œœ˜%JšœœÏc@˜^Jšœž)˜HJšœ œœž=˜UJšœœž˜9Jšœ œž ˜4J˜J˜—Jšœœ˜J˜—™ J˜šÏnœœœœ ˜Y™J™J™2—J™2J™UJ™CJ™^—J˜šŸœœ&œ#˜[Jšœ˜ JšœD™D—J™š Ÿ œœœœœ˜DJš œœœœœ˜6J™,—J˜šŸœœ˜!J™(—J˜šŸ œœ'˜:Jš œ œ,œœœ ˜ZJšœO™OJ™6—J˜JšŸœœ(˜=J˜š Ÿœœœœ˜=Jšœœ˜&J™N—J˜—Jšœ˜J˜—…— ²