home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
lan
/
critical
/
critical.asm
next >
Wrap
Assembly Source File
|
1988-07-15
|
5KB
|
224 lines
TITLE CRITICAL -- Critical process coordinamtion routines
PAGE 61,132
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; CRITICAL.ASM - Critical process coordination routines
;
; Written by Scott Chamberlain, (C) 1988, all rights reserved
;
; This module will let us make sure that multiple users on a Novell
; Netware network don't execute the same critical code section simultaneously
;
; Requires:
; Microsoft MASM 3.0
; Clipper Summer '87
; Novell Netware 4.6 or above (all Advanced Netware versions)
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INCLUDE extenda.mac
INCLUDE extenda2.mac
PUBLIC INITCRIT,CRITNUMS,STCRIT,ENDCRIT,CLOSCRIT
DGROUP GROUP DATASG
DATASG SEGMENT 'DATA'
S_HNDL_CX dw 0ffffH ; storage place for opened semaphore handle
S_HNDL_DX dw 0ffffH ;
NUM_STA db 0 ; number of stations with opened handle
S_VALUE db 1
STR_SEG dw ? ; segment of handle name string from Clipper
STR_OFF dw ? ; offset of handle name string from Clipper
S_NAME_LEN db 0
S_NAME db 127 dup(0)
DATASG ENDS
_PROG SEGMENT 'CODE'
ASSUME cs:_PROG,ds:DGROUP
INITCRIT PROC FAR
;
; Push required registers
PUSHREGS
push ax
push bx
push cx
push dx
;
; Get the parameter count
GET_PCOUNT
;
; Check for correct # of parameters
cmp ax,1
jz CHK_PTYPE
mov bx,1 ; signal for bad number of parameters
jmp INITEXIT
;
; Check for parameter to be type *char ("pointer to char")
CHK_PTYPE:
GET_PTYPE 1
cmp ax,CHARACTER
jz IS_NAME
mov bx,2 ; signal for bad parameter type
jmp INITEXIT
;
; Get the length of the string parameter
IS_NAME:
GET_CLEN 1 ; length in AX
CMP AX,127
JBE LEN_OK
MOV S_NAME_LEN,127
;
; Get the address of the string parameter
LEN_OK:
GET_CHAR 1 ; string seg:AX offset:BX
mov STR_SEG,ax
mov STR_OFF,bx
;
; Now, transfer the string to the holding area
xor ch,ch ;clear the high part of the count
mov cl,S_NAME_LEN ;move the length into the low part of the count
mov ax,ds ;point es:di at our buffer
mov es,ax
mov di,OFFSET S_NAME
mov si,STR_OFF ;point ds:si at the Clipper string
mov ax,STR_SEG
mov ds,ax
rep movsb ;move the string into the buffer
;
; Now, set up for the Netware Open Semaphore call
mov ax,es ;point back to the correct data segment
mov ds,ax
mov dx,OFFSET S_NAME_LEN
mov cl,S_VALUE
;
; Open the semaphore
mov ax,0C500H ; request Open Semaphore
int 21H
;
; Check for completion code
cmp al,0
JZ open_ok
;
; Error returned from Netware call - return error number
xor bx,bx
mov bl,al
jmp INITEXIT
OPEN_OK:
;
; Semaphore has been opened without error. Save semaphore information
mov S_HNDL_CX,cx
mov S_HNDL_DX,dx
mov NUM_STA,bl
xor bx,bx ; indicate correct operation
INITEXIT:
RET_INT bx ; return operation status
pop dx
pop cx
pop bx
pop ax
POPREGS
ret
INITCRIT ENDP
CRITNUMS PROC FAR
;
; Returns the number of stations having opened the semaphore
PUSHREGS
push bx
xor bx,bx
mov bl,NUM_STA
RET_INT bx
pop bx
POPREGS
ret
CRITNUMS ENDP
STCRIT PROC FAR
;
; This procedure will allow us to check to see if we can enter a critical
; module without conflicting with others who want to use that module.
PUSHREGS
push ax
push cx
push dx
push bp
;
; Set up for Netware semaphore check
mov cx,S_HNDL_CX ; get the semaphore handle
mov dx,S_HNDL_DX
mov bp,180 ; ten second waiting period
mov ax,0C502H ; request Semaphore: Decrement and Wait if Negative
int 21H
xor ah,ah ; clear AH - AL is return code
RET_INT ax
pop bp
pop dx
pop cx
pop ax
POPREGS
ret
STCRIT ENDP
ENDCRIT PROC FAR
;
; This procedure signals that we are finished with the critical module, and
; releases the semaphore for someone else's use
PUSHREGS
push ax
push cx
push dx
;
; Set up for Netware semaphore release
mov cx,S_HNDL_CX ; semaphore handle
mov dx,S_HNDL_DX
mov ax,0C503H ; request Semaphore: Increment and Release if Waiting
int 21H
xor ah,ah
RET_INT ax
pop dx
pop cx
pop ax
POPREGS
ret
ENDCRIT ENDP
CLOSCRIT PROC FAR
; releases a semaphore from use
PUSHREGS
push ax
push cx
push dx
;
; Set up for Netware semaphore close
mov cx,S_HNDL_CX ; semaphore handle
mov dx,S_HNDL_DX
mov ax,0C504H ; request Close Semaphore
INT 21H
xor ah,ah
RET_INT ax
pop dx
pop cx
pop ax
POPREGS
ret
CLOSCRIT ENDP
_PROG ENDS
END