;       SCCSID = @(#)sswlokck.asm	6.1 90/11/18

;      SCCSID = @(#)sswlokck.asm	6.3 90/03/19
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************

	 page 60,132

;********************** START OF SPECIFICATIONS ***********************/
;								      */
; SOURCE FILE NAME: SSWLOKCK					      */
;								      */
; SUBROUTINE NAME:  SSLockCheck 				      */
;								      */
; DESCRIPTIVE NAME:  Screen Switcher's screen lock testing            */
;		     procedure. 				      */
;								      */
; FUNCTION: This is an internally called procedure which initiates    */
;	    timing of the lock in effect by a screen group. If the    */
;	    lock timing indicates a timeout, the process is frozen.   */
;								      */
; NOTES:  Executes on Level 3					      */
;								      */
; ENTRY POINT:	SSLockCheck					      */
;   LINKAGE:							      */
;								      */
; INPUT: DS points to common data segment. DI points to sgcb.	      */
;								      */
; EXIT-NORMAL:	None						      */
;								      */
; EXIT-ERROR:	None						      */
;								      */
; EFFECTS:  None						      */
;								      */
; INTERNAL REFERENCES:						      */
;   ROUTINES:  None						      */
;								      */
; EXTERNAL REFERENCES:						      */
;   ROUTINES:  DosSemSet, DosTimerStart, DosTimerStop, DosSemWait     */
;								      */
;	Change History: 					      */
;								      */
;	@TL6 - 03/01/90 - DCR 704 - Merge SMG/SSW instance data into  */
;			  OS2CHAR				      */
;								      */
;								      */
;*********************** END OF SPECIFICATIONS ************************/
EXTRN locktime:word, timedouterror:word
EXTRN subfunction:word, actionpacket:word, responsepacket:word
EXTRN screenlocksgid:word, savelockowner:word
EXTRN lockfrozen:word, procid:word
EXTRN locktimersem:dword
EXTRN savelocksem:dword
EXTRN VIOSSWSWITCH:FAR	      ; Added on 7/14/87 to clear/grab sg's sems

.xlist
INCLUDE SSWINC.INC
.list

.386p

CODE	SEGMENT WORD PUBLIC 'CODE' USE16                                ;@TL6

	ASSUME	CS:CODE, DS:NOTHING,SS:NOTHING,ES:NOTHING		;@TL6

	 PUBLIC  SSLOCKCHECK

SSLOCKCHECK    PROC    NEAR

	 push	 bx
	 push	 cx
	 xor	 cx,cx

;***************************************************************************
;  The following VIO call was added on 7/14/87 to take care of what was
;  a permanent restriction. The restriction forbade an application from
;  issuing any VIO calls if it had issued a VIOSCRNLOCK which was still
;  in effect. The call with a pushed 0 clears the screen groups semaphores.
;***************************************************************************

	 push	 cx			; We tell VIO to clear the sg's ;@TL6
	 call	 VIOSSWSWITCH		; semaphores

	 push	 ds			; c 7/23/86
	 push	 offset locktimersem	; c 7/23/86
	 call	 DOSSEMSET		; start countdown
	 .IF <[di].sglockineffect ne 0> ; one per screen group
	    push    ds
	    push    offset locktimersem
	    push    0			; Need DD value
	    push    locktime		; value = -1
	    call    DOSSEMWAIT		; wait for semaphore -
	    .IF <zero ax> OR						;@TL6
	    .IF <ax e error_sem_timeout>

;***************************************************************************
; The final call with a pushed 1 tells VIO to grab the screen group's
; semaphores again.
;***************************************************************************
					      ; ES9/14/87
	       push    1		      ; We tell VIO to reclaim the
	       call    VIOSSWSWITCH	      ; sg's semaphores

	       .IF <[di].sglockineffect ne 0>  ; one per screen group
		  mov	  cx,3		; Lock timeout error
		  mov	  ax,[di].sglockineffect  ; Get the pid
		  mov	  procid,ax	; store pid in action
		  mov	  subfunction,0  ; freeze process

		  push	  0		; Sesmgr. service cat.
		  push	  ds		; function
		  push	  offset actionpacket
		  push	  ds		; stack
		  push	  offset responsepacket
		  call	  DOSSYSTEMSERVICE  ; Freeze in background
		  .IF <zero ax> 					;@TL6
		     mov     lockfrozen,1
		     mov     ax,[di].sglockineffect
		     mov     [di].sgprocessfrozen,ax
		     xor     ax,ax
		  .ENDIF
	       .ENDIF
	    .ELSE
	       push    1		      ; We tell VIO to reclaim the
	       call    VIOSSWSWITCH	      ; sg's semaphores
	    .ENDIF
	    .IF <zero ax>						;@TL6
	       xchg    ax,cx
	    .ENDIF
	 .ELSE
	    push    1			   ; We tell VIO to reclaim the
	    call    VIOSSWSWITCH	   ; sg's semaphores

	    push    ds
	    push    offset locktimersem
	    call    DOSSEMCLEAR
	 .ENDIF

	 pop	 cx
	 pop	 bx

	 ret

SSLOCKCHECK    ENDP

CODE	ENDS								;@TL6
	 END
