;       SCCSID = @(#)proc.asm	6.2 91/10/20
;      SCCSID = @(#)proc.asm	6.2 91/10/20
;***	proc - interface to ProcBlock and ProcRun
;
;	ProcBlock - block current thread execution until a matching ProcRun
;
;	ProcRun - awaken all blocked threads with matching ID
;
;	ProcRun2 - awaken all blocked threads with matching ID and
;                  give them an IO-boost
;

.286

.MODEL MEDIUM, PASCAL

ifdef MEDIUM_MODEL
CALLTYPE    equ <far>
else
CALLTYPE    equ <near>
endif

include devhlp.inc
include error.inc
include proc.inc

.data

extrn pDevHlp:dword

IRP SEG,<_TEXT,_BTXT>

.CODE SEG


;**	ProcBlock - block current thread until matching ProcRun
;
;	void ProcBlock (PVOID id);
;
;	Returns when a ProcRun with matching ID is issued
;
;	Non-interruptible, no timeout

public ProcBlock&SEG
ProcBlock&SEG   proc CALLTYPE    uses di,	\
    id:dword

	xor	ax,ax
	mov	es,ax		    ; zero es to avoid GP fault
	mov	bx,word ptr (id)
	mov	ax,word ptr (id+2)  ; (ax:bx) = ID to block on

	mov	cx,-1
	mov	di,cx		    ; (di:cx) = infinite timeout

	mov	dh,1		    ; (dh) = 1 (non-interruptible)
	mov	dl,DevHlp_ProcBlock ; (dl) = function code

	call	pDevHlp 	    ; Block until awoken

	ret

ProcBlock&SEG   endp



;**	ProcRun - awaken all blocked threads with matching ID
;
;	void ProcRun (PVOID id);
;
;	Returns none
;

public ProcRun&SEG
ProcRun&SEG proc CALLTYPE 			\
    id:dword

	xor	ax,ax
	mov	es,ax		    ; zero es to avoid GP fault
	mov	bx,word ptr (id)
	mov	ax,word ptr (id+2)  ; (ax:bx) = ID to awaken

	mov	dl,DevHlp_ProcRun   ; (dl) = function code

	call	pDevHlp 	    ; awaken all matching blockers

	ret

ProcRun&SEG endp



;**	ProcBlockTime- block current thread until matching ProcRun or Timeout
;
;	USHORT ProcBlock (PVOID id, ULONG timeout);
;
;	Returns when a ProcRun with matching ID is issued or timeout occurs.
;
;	Interruptible
;
;	(ax) = error code
;

public ProcBlockTime&SEG
ProcBlockTime&SEG	proc CALLTYPE 	uses di,    \
    id:dword, \
    timeout:dword

	xor	ax,ax
	mov	es,ax		    ; zero es to avoid GP fault
	mov	bx,word ptr (id)
	mov	ax,word ptr (id+2)	; (ax:bx) = ID to block on

	mov	cx,word ptr (timeout)
	mov	di,word ptr (timeout+2) ; (di:cx) = timeout

	mov	dh,0			; (dh) = 0 (interruptible)
	mov	dl,DevHlp_ProcBlock	; (dl) = function code

	call	pDevHlp 		; Block until awoken

	jc pbt10			; exit with error

	xor	ax,ax			; exit with no error
	ret

pbt10:	jnz	pbt20			; exit with unusual error

	mov	ax,ERROR_SEM_TIMEOUT	; exit with timeout
	ret

pbt20:	mov	ax,ERROR_INTERRUPT	; return with interrupt

	ret

ProcBlockTime&SEG	endp


;**	ProcRun2 - awaken all I/O blocked threads with matching ID
;
;	void ProcRun2 (PVOID id);
;
;	Returns none
;

public ProcRun2&SEG
ProcRun2&SEG proc    CALLTYPE                \
    id:dword

	xor	ax,ax
	mov	es,ax		    ; zero es to avoid GP fault
	mov	bx,word ptr (id)
	mov	ax,word ptr (id+2)  ; (ax:bx) = ID to awaken

	mov	dl,DevHlp_ProcRun2  ; (dl) = function code

	call	pDevHlp 	    ; awaken all matching blockers

	ret

ProcRun2&SEG endp

ENDM
end
