DIRECTORY ProcessProps USING [], List USING [AList]; ProcessPropsImpl: CEDAR MONITOR EXPORTS ProcessProps = BEGIN OPEN List; AddPropList: PUBLIC PROC [propList: AList, inner: PROC] = TRUSTED { old: AList = NARROW[GetProcessProperty[]]; IF old # NIL THEN { tail: AList ¬ NIL; FOR each: AList ¬ propList, each.rest WHILE each # NIL DO new: AList = LIST[each.first]; IF tail = NIL THEN propList ¬ new ELSE tail.rest ¬ new; tail ¬ new; ENDLOOP; IF tail = NIL THEN propList ¬ old ELSE tail.rest ¬ old; }; SetProcessProperty[propList]; inner[! UNWIND => SetProcessProperty[old]]; SetProcessProperty[old]; }; PushPropList: PUBLIC PROC [propList: AList, inner: PROC] = { old: AList = NARROW[GetProcessProperty[]]; SetProcessProperty[propList]; inner[! UNWIND => SetProcessProperty[old]]; SetProcessProperty[old]; }; GetPropList: PUBLIC PROC RETURNS [propList: AList ¬ NIL] = TRUSTED { propList ¬ NARROW[GetProcessProperty[]]; }; GetProp: PUBLIC PROC [key: REF] RETURNS [prop: REF ¬ NIL] = TRUSTED { propList: AList ¬ NARROW[GetProcessProperty[]]; WHILE propList # NIL DO IF propList.first.key = key THEN RETURN [propList.first.val]; propList ¬ propList.rest; ENDLOOP; }; GetProcessProperty: PROC RETURNS [prop: REF] ~ TRUSTED MACHINE CODE { "XR_GetThreadProperty" }; SetProcessProperty: PROC [prop: REF] ~ TRUSTED MACHINE CODE { "XR_SetThreadProperty" }; END. x ProcessPropsImpl.mesa Copyright Σ 1985, 1986, 1991 by Xerox Corporation. All rights reserved. Russ Atkinson, February 1, 1985 3:53:26 pm PST Carl Hauser, June 30, 1988 10:30:33 pm PDT ... adds the given properties to the current process for the duration of the call of inner. The old property list for the process will not be altered, but will be found at the end of the propety list during the call to inner. The old property list will be restored after the call has completed. The new propList will be copied if an old property list exists. ... sets the property list for the current process for the duration of the call of inner. The old property list will be restored after the call has completed. The new propList will not be copied. Most applications should use AddPropList to properly inherit properties. ... returns the current property list for the current process. Although there is no prohibition from altering the returned list, users are encouraged to follow the style of adding new properties, rather than changing old associations. ... returns the current property associated with the given key for the current process. This procedure is preferred to GetPropList for most applications. The following two operations are safe, but operations on PROCESS values are, in general, not safe, since processes are reused. These operations should be regarded as instantaneous samples, where the results are likely to change without notice. However, statistics-style applications and may find these operations useful despite these caveats. It is also OK to ask whether a process still has some property if that property will not be reused. GetSpecificPropList: PUBLIC PROC [process: PROCESS] RETURNS [propList: AList _ NIL] = TRUSTED { ... returns the current property list for the specified process entry: ProcessEntry = GetProcessEntry[process]; IF entry # NIL THEN propList _ entry.current; }; GetNextPropList: PUBLIC ENTRY PROC [process: PROCESS _ NIL] RETURNS [next: PROCESS _ NIL, propList: AList _ NIL] = { ... returns the next process with a non-NIL propList. Use GetNextPropList[NIL] to start the iteration. [NIL, NIL] will be returned if no more processes exist. The processes are produced in increasing order. There is a very small probability of a race with AddPropList and PushPropList, but it must result in a bounded number of retries. ENABLE UNWIND => NULL; DO best: ProcessEntry _ NIL; FOR i: NAT IN [0..16) DO FOR each: ProcessEntry _ processVector[i], each.next UNTIL each = NIL DO eachProcess: CARDINAL = LOOPHOLE[each.process]; IF each.current = NIL THEN LOOP; IF eachProcess <= LOOPHOLE[process, CARDINAL] THEN LOOP; IF best = NIL OR eachProcess < LOOPHOLE[best.process, CARDINAL] THEN best _ each; ENDLOOP; ENDLOOP; IF best = NIL THEN EXIT; propList _ best.current; IF propList = NIL THEN {races _ races + 1; LOOP}; -- rats! a race occurred next _ best.process; EXIT; ENDLOOP; }; Κj–(cedarcode) style•NewlineDelimiter ™codešœ™Kšœ Οeœ=™HKšœ.™.K™*—K˜šΟk ˜ Kšœ žœ˜Kšœžœ ˜K˜—šΟnœžœž˜Kšžœ ˜Kšœžœžœ˜K˜—šŸ œž œžœžœ˜CKšœι™ιKšœ žœ˜*šžœžœžœ˜Kšœžœ˜šžœ#žœžœž˜9Kšœ žœ ˜Kšžœžœžœžœ˜7Kšœ ˜ Kšžœ˜—Kšžœžœžœžœ˜7K˜—Kšœ˜Kšœžœ˜+Kšœ˜K˜K˜—šŸ œžœžœžœ˜Kšœ?™?Kšœ/™/Kšžœ žœžœ™-K™K™—šŸœžœžœžœ žœžœžœžœžœžœ™tKšœΤ™ΤKšžœžœžœ™šž™Kšœžœ™šžœžœžœ ž™šžœ2žœžœž™HKšœ žœžœ™/Kšžœžœžœžœ™ Kš žœžœ žœžœžœ™8š žœžœžœžœžœ™?Kšžœ ™—Kšžœ™—Kšžœ™—Kšžœžœžœžœ™Kšœ™Kš žœ žœžœžœΟc™KKšœ™Kšžœ™Kšžœ™—K™K™K˜—Kšžœ˜K˜—…—R4