-- TiogaRefreshImpl.mesa Edited by Paxton on June 14, 1983 3:41 pm
Last Edited by: Maxwell, January 6, 1983 11:35 am
DIRECTORY
TiogaRefresh,
MonitoredQueue USING [Create, MQ, Remove],
Process USING [Detach, SetPriority, priorityNormal],
TiogaDocument USING [GetViewerForRoot, SelectionId, TiogaDocumentData],
TiogaLocks USING [RegisterForCallAfterReleaseWriteLock],
TiogaNode USING [Ref],
TiogaTouchup USING [refresh, RefreshOver],
ViewerClasses USING [Viewer],
ViewerOps USING [PaintViewer];
TiogaRefreshImpl: CEDAR MONITOR
IMPORTS MonitoredQueue, Process, TiogaDocument, TiogaLocks, TiogaTouchup, ViewerOps
EXPORTS TiogaRefresh = BEGIN
dirtyDocs: PUBLIC MonitoredQueue.MQ ← MonitoredQueue.Create[];
processCount, scrollProcessCount: INTEGER ← 0;
maxProcesses: INTEGER = 10; -- max number of concurrent refresh processes
done: CONDITION;
DecCount: ENTRY PROC = {
processCount ← processCount-1; NOTIFY done };
Refresh: PROC = { 
TRUSTED {Process.SetPriority[Process.priorityNormal]};
DO
doc: TiogaNode.Ref;
viewer: ViewerClasses.Viewer;
RefreshIt: ENTRY PROC [viewer: ViewerClasses.Viewer] = {
WHILE processCount >= maxProcesses DO WAIT done; ENDLOOP;
processCount ← processCount+1;
TRUSTED {Process.Detach[FORK RefreshViewer[viewer ! ABORTED => CONTINUE]]} };
doc ← NARROW[MonitoredQueue.Remove[dirtyDocs]];
viewer ← TiogaDocument.GetViewerForRoot[doc];
IF viewer=NIL THEN LOOP;
RefreshIt[viewer];
IF viewer.link # NIL THEN
FOR v: ViewerClasses.Viewer ← viewer.link, v.link UNTIL v=viewer DO
RefreshIt[v]; ENDLOOP;
ENDLOOP };
RefreshViewer: PROC [viewer: ViewerClasses.Viewer] = {
tdd: TiogaDocument.TiogaDocumentData = NARROW[viewer.data];
IF tdd = NIL THEN RETURN;
[] ← TiogaLocks.LockDocAndTdd[tdd, "RefreshViewer", read];
tdd.invisible ← TRUE; -- will be reset by our paint proc if it is called
ViewerOps.PaintViewer[viewer, client, FALSE, TiogaTouchup.refresh];
IF tdd.invisible THEN TiogaTouchup.RefreshOver[];
in case we're waiting in LockAfterRefresh
DecCount[];
TiogaLocks.UnlockDocAndTdd[tdd] };
ScrollToEndOfDoc: PUBLIC PROC [viewer: ViewerClasses.Viewer, glitch: BOOL] = {
tdd: TiogaDocument.TiogaDocumentData = NARROW[viewer.data];
tdd.scroll ← endofdoc; tdd.scrollGlitch ← glitch };
ScrollToEndOfSel: PUBLIC PROC [viewer: ViewerClasses.Viewer, glitch: BOOL,
id: TiogaDocument.SelectionId ← primary] = {
tdd: TiogaDocument.TiogaDocumentData = NARROW[viewer.data];
tdd.scroll ← endofsel; tdd.scrollGlitch ← glitch; tdd.scrollSelectionId ← id };
DirtyDoc: PROCEDURE [doc: TiogaNode.RefBranchNode] = {
viewer: ViewerClasses.Viewer;
IF (viewer ← TiogaDocument.GetViewerForRoot[doc]) # NIL THEN {
MarkDirty: PROC [v: ViewerClasses.Viewer] = {
tdd: TiogaDocument.TiogaDocumentData ← NARROW[v.data];
IF tdd#NIL THEN tdd.dirty ← TRUE };
MarkDirty[viewer];
IF viewer.link # NIL THEN
FOR v: ViewerClasses.Viewer ← viewer.link, v.link UNTIL v=viewer DO
MarkDirty[v]; ENDLOOP;
MonitoredQueue.AddToSet[doc, dirtyDocs] };
};
TRUSTED {Process.Detach[FORK Refresh[]]};
TiogaLock.RegisterForCallAfterReleaseWriteLock[DirtyDoc];
END.