DIRECTORY Commander, Loader, Menus, PrincOps, PrincOpsUtils, Process, ReadEvalPrint, Rope, UserProfile, ViewerClasses, ViewerOps; CommanderPriority: CEDAR PROGRAM IMPORTS Commander, Loader, Menus, PrincOpsUtils, Process, UserProfile, ViewerOps = BEGIN ROPE: TYPE = Rope.ROPE; Handle: TYPE = ReadEvalPrint.Handle; PDA: PrincOps.PDABase = PrincOps.PDA; normalButtonName, foregroundButtonName, backgroundButtonName: ROPE; NoteProfile: PROC [reason: UserProfile.ProfileChangeReason] --UserProfile.ProfileChangedProc-- = { normalButtonName _ UserProfile.Token["CommanderPriority.NormalButtonName", "N"]; foregroundButtonName _ UserProfile.Token["CommanderPriority.ForegroundButtonName", "F"]; backgroundButtonName _ UserProfile.Token["CommanderPriority.BackgroundButtonName", "B"]; }; Background: Menus.MenuProc = { h: Handle _ NARROW[clientData, Handle]; [] _ ResetPriority[h.mainLoopProcess, Process.priorityBackground ! Process.InvalidProcess => CONTINUE]; }; Foreground: Menus.MenuProc = { h: Handle _ NARROW[clientData, Handle]; [] _ ResetPriority[h.mainLoopProcess, Process.priorityForeground ! Process.InvalidProcess => CONTINUE]; }; Normal: Menus.MenuProc = { h: Handle _ NARROW[clientData, Handle]; [] _ ResetPriority[h.mainLoopProcess, Process.priorityNormal ! Process.InvalidProcess => CONTINUE]; }; ResetPriority: PROC [process: PROCESS, new: PrincOps.Priority] RETURNS [success: BOOL _ TRUE] = TRUSTED { old: PrincOps.Priority; psb: PrincOps.PsbHandle; psb _ PrincOpsUtils.PsbIndexToHandle[LOOPHOLE[process]]; PrincOpsUtils.DisableInterrupts[]; old _ PDA[psb].link.priority; IF old # new THEN { self: PrincOps.PsbHandle = PrincOpsUtils.PsbIndexToHandle[ PDA[PrincOpsUtils.PsbIndexToHandle[PDA.ready.tail]].link.next]; npsb: PrincOps.PsbHandle _ PrincOpsUtils.PsbIndexToHandle[PDA[self].link.next]; IF PDA[psb].link.vector THEN { nsv: PrincOps.StateVectorHandle _ PDA.state[new]; IF nsv = PrincOps.NullStateVectorHandle THEN GO TO fail; PDA.state[new] _ LOOPHOLE[PDA[nsv].stk[0]]; PDA[nsv].stk[0] _ LOOPHOLE[PDA.state[old]]; PDA.state[old] _ nsv; }; PDA[psb].link.priority _ new; DO IF npsb = self THEN EXIT; IF npsb = psb THEN { PrincOpsUtils.Requeue[@PDA.ready, @PDA.ready, psb]; EXIT; }; npsb _ PrincOpsUtils.PsbIndexToHandle[PDA[npsb].link.next]; ENDLOOP; EXITS fail => {success _ FALSE}; }; PrincOpsUtils.EnableInterrupts[]; }; Greet: PROC [handle: Handle, cmd: Commander.Handle, paint: BOOL] = { v: ViewerClasses.Viewer _ handle.viewer; Add: PROC [me: Menus.MenuEntry, name: ROPE] = { old: Menus.MenuEntry = Menus.FindEntry[v.menu, name]; IF old = NIL THEN Menus.AppendMenuEntry[v.menu, me] ELSE Menus.ReplaceMenuEntry[v.menu, old, me]; }; Add[Menus.CreateEntry[name: normalButtonName, proc: Normal, fork: TRUE, clientData: handle], normalButtonName]; Add[Menus.CreateEntry[name: foregroundButtonName, proc: Foreground, fork: TRUE, clientData: handle], foregroundButtonName]; Add[Menus.CreateEntry[name: backgroundButtonName, proc: Background, fork: TRUE, clientData: handle], backgroundButtonName]; IF paint THEN ViewerOps.PaintViewer[v, menu]; }; CommanderPriorityCmdProc: Commander.CommandProc ~ { handle: ReadEvalPrint.Handle _ NARROW[ Commander.GetProperty[$ReadEvalPrintHandle, cmd.propertyList]]; Greet[handle, cmd, TRUE]; }; Loader.MakeProcedureResident[ResetPriority]; UserProfile.CallWhenProfileChanges[NoteProfile]; Commander.Register[key: "///Commands/CommanderPriority", proc: CommanderPriorityCmdProc, doc: "registers CommandTool menu buttons priority changes."]; END. 4CommanderPriority.mesa Copyright c 1986 by Xerox Corporation. All rights reserved. Bob Hagmann January 31, 1986 9:11:47 am PST [parent: REF, clientData: REF, mouseButton: MouseButton, shift, control: BOOL] [parent: REF, clientData: REF, mouseButton: MouseButton, shift, control: BOOL] [parent: REF, clientData: REF, mouseButton: MouseButton, shift, control: BOOL] This routine sets the priority of the specified process. This routine was stolen from CollectorWatchdogImpl. We need to preserve the number of state vectors at various priorities. The easiest way to do this is to transfer a state vector from the new priority list to the old priority list, which allows the current state vector to remain with the process. If there is no available state vector at that priority, then we lose. Remove the new state vector from its priority chain Give the new state vector to the old priority chain. At this point we can alter the priority and assume success. If the process that is getting its priority changed is on the ready queue we must remove it from the queue and put it back, thereby changing its position in the queue. If it was not on the ready queue, we hope that changing its priority did not upset someone who was depending on priorities being sorted within other kinds of queues. We will see what we will see! Κό˜codešœ™Kšœ Οmœ1™žœ˜CK˜K˜šΟn œžœ+Οc"œ˜bKšœP˜PKšœX˜XKšœX˜XK˜—˜K˜—šΟb œ˜KšœN™NKšœ žœ˜'Kšœ]žœ˜gKšœ˜—š‘ œ˜KšœN™NKšœ žœ˜'Kšœ]žœ˜gKšœ˜—š‘œ˜KšœN™NKšœ žœ˜'KšœYžœ˜cKšœ˜—K˜šŸ œž˜Kš œ žœžœ žœžœžœ˜UK™8Kšœ3™3Kšœ˜Kšœ˜Kšœ%žœ ˜8Kšœ"˜"Kšœžœ˜K˜šžœ žœ˜šœ:˜:Kšžœ žœ˜?—Kšœ:žœ˜OK˜šžœžœžœ˜Kšœχ™χK˜Kšœ"žœ ˜1šžœ&žœžœžœ˜8KšœE™E—K˜Kšœ3™3Kšžœžœžœ˜+K˜Kšœ4™4Kšžœžœžœ ˜+Kšžœ˜K˜K˜K˜—Kšœ;™;Kšžœ˜K˜Kšœν™νšž˜Kšžœ žœžœ˜šžœ žœ˜Kšœžœ žœ ˜3Kšžœ˜K˜—Kšœ&žœ˜;Kšžœ˜K˜—Kšžœžœ˜ K˜—K˜!K˜K˜K˜—šŸœžœ0žœ˜DKšœ(˜(šŸœžœžœ˜/Kšœ5˜5šžœž˜ Kšžœ"˜&Kšžœ)˜-—K˜—KšœBžœ)˜oKšœJžœ+˜{KšœJžœ+˜{Kšžœžœ ˜-K˜—K˜K˜K˜š‘œ˜3KšœžœA˜fKšœžœ˜K˜—K˜Kšœ,˜,K˜Kšœ0˜0K˜KšœΟrœ`˜–—K˜K˜Kšžœ˜K™—…— Δτ