Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-08 - 43,50512/next.b36
There are no other files named next.b36 in the archive.
MODULE NEXT=
!Routines to do process exchange
!Environment: TOPS-10 (should be transportable)
!Author: Andrew Nourse
BEGIN
!
!Table of contents
!
FORWARD ROUTINE
	WAIT,		!Wait for something to happen to us
	NEXTP;		!Find the next process to run & run it

!
!Library & Require files
!
REQUIRE 'INTR.REQ';
UNDECLARE %QUOTE NEXT;

!
!Version info
!
THIS_IS [NEXT]		VERSION [2]	EDIT [2]	DATE [10,OCT,79]
![2]	Validate process handles before using them
!	Requires at least CPROC v2

!
! Externals
!
EXTERNAL ROUTINE
	CLKCHK,
	PICKUP,
	CHECKF,		!Check if a number is really a process handle
	EXCHANGE;


GLOBAL ROUTINE WAIT(WHATFOR)=
!Routine to put a process into a 'wait state'
!WHATFOR is the address of an interrupt block
BEGIN
EXTERNAL ROUTINE %NAME('.SIGNL');
EXTERNAL RUN: REF PROCESS_BLOCK;
REGISTER T: REF INT_BLOCK;
RUN[P$WAIT]=.WHATFOR;	!Save what we are waiting for
DO	BEGIN
	NEXTP();
	WHILE (T=.RUN[P$INTERRUPTS]) NEQ 0 DO BEGIN
		RUN[P$INTERRUPTS]=.T[INT$NEXT];
		!Move next interrupt to top of chain
		%NAME('.SIGNL')(T[INT$SIGNAL_ARGS]);
		END;
	END WHILE .RUN[P$WAIT] NEQ 0;
END;
GLOBAL ROUTINE NEXTP=
!Routine to find the next process and continue it,
! or hibernate if none
BEGIN
EXTERNAL RUN: REF PROCESS_BLOCK;
EXTERNAL ROUTINE HIBERNATE;
EXTERNAL ROUTINE EXCHANGE;	!Routine to swap stacks
REGISTER T;
NOINTS((	!Interrupts during stack munging could be bad news
	T=.RUN[P$NEXT];
	RUN[P$NEXT]=0;	!Next job is soon to become current job
	RUN=.T;	!Right now, in fact.  Pass new routine its stack addr

	WHILE CHECKF(.RUN) EQL 0 !As long as there is nothing to do...
	 DO	BEGIN
		EXTERNAL ROUTINE CLKCHK;
		RUN=0;		!In case it was invalid, not 0.
		CLKCHK();	!See if anyone wants to be aWAKEned
		IF .RUN EQL 0 THEN PICKUP();!Pickup dropped interrupts, if any
		IF .RUN EQL 0	!If still nothing to do, go to sleep
		THEN	BEGIN
			INTERRUPTS[ON];
			HIBERNATE();
			INTERRUPTS[OFF]
			END;
		END;
EXCHANGE(.RUN[P$STK],WIN);
));!NOINTS
END;
END ELUDOM