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 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]; 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]; END.  TEditLocks.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Edited by Paxton on October 20, 1982 7:35 am Last Edited by: Maxwell, January 6, 1983 10:32 am Michael Plass, March 21, 1985 3:06:58 pm PST Doug Wyatt, March 3, 1985 1:54:24 pm PST 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. Κ˜codešœ™Kšœ Οmœ1™