home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / critical / critical.asm next >
Assembly Source File  |  1988-07-15  |  5KB  |  224 lines

  1. TITLE CRITICAL -- Critical process coordinamtion routines
  2. PAGE  61,132
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. ;
  5. ;  CRITICAL.ASM  -  Critical process coordination routines
  6. ;
  7. ;  Written by Scott Chamberlain, (C) 1988, all rights reserved
  8. ;
  9. ;  This module will let us make sure that multiple users on a Novell
  10. ;  Netware network don't execute the same critical code section simultaneously
  11. ;
  12. ;  Requires:
  13. ;     Microsoft MASM 3.0
  14. ;     Clipper Summer '87
  15. ;     Novell Netware 4.6 or above (all Advanced Netware versions)
  16. ;
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18.  
  19. INCLUDE  extenda.mac
  20. INCLUDE  extenda2.mac
  21.  
  22. PUBLIC   INITCRIT,CRITNUMS,STCRIT,ENDCRIT,CLOSCRIT
  23.  
  24. DGROUP   GROUP    DATASG
  25.  
  26. DATASG   SEGMENT  'DATA'
  27.  
  28. S_HNDL_CX   dw 0ffffH           ; storage place for opened semaphore handle
  29. S_HNDL_DX   dw 0ffffH           ;
  30.  
  31. NUM_STA     db 0                ; number of stations with opened handle
  32.  
  33. S_VALUE     db 1
  34.  
  35. STR_SEG     dw ?                ; segment of handle name string from Clipper
  36. STR_OFF     dw ?                ; offset of handle name string from Clipper
  37.  
  38. S_NAME_LEN  db 0
  39. S_NAME      db 127 dup(0)
  40.  
  41. DATASG   ENDS
  42.  
  43. _PROG    SEGMENT 'CODE'
  44.      ASSUME   cs:_PROG,ds:DGROUP
  45.  
  46. INITCRIT PROC     FAR
  47. ;
  48. ;  Push required registers
  49.      PUSHREGS
  50.      push     ax
  51.      push     bx
  52.      push     cx
  53.      push     dx
  54. ;
  55. ;  Get the parameter count
  56.      GET_PCOUNT
  57. ;
  58. ;  Check for correct # of parameters
  59.      cmp   ax,1
  60.      jz    CHK_PTYPE
  61.      mov   bx,1              ; signal for bad number of parameters
  62.      jmp   INITEXIT
  63. ;
  64. ;  Check for parameter to be type *char ("pointer to char")
  65. CHK_PTYPE:
  66.      GET_PTYPE   1
  67.      cmp   ax,CHARACTER
  68.      jz    IS_NAME
  69.      mov   bx,2              ; signal for bad parameter type
  70.      jmp   INITEXIT
  71. ;
  72. ;  Get the length of the string parameter
  73. IS_NAME:
  74.      GET_CLEN    1           ; length in AX
  75.      CMP   AX,127
  76.      JBE   LEN_OK
  77.      MOV   S_NAME_LEN,127
  78. ;
  79. ;  Get the address of the string parameter
  80. LEN_OK:
  81.      GET_CHAR    1           ; string seg:AX offset:BX
  82.      mov   STR_SEG,ax
  83.      mov   STR_OFF,bx
  84. ;
  85. ;  Now, transfer the string to the holding area
  86.      xor   ch,ch             ;clear the high part of the count
  87.      mov   cl,S_NAME_LEN     ;move the length into the low part of the count
  88.      mov   ax,ds             ;point es:di at our buffer
  89.      mov   es,ax
  90.      mov   di,OFFSET S_NAME
  91.      mov   si,STR_OFF        ;point ds:si at the Clipper string
  92.      mov   ax,STR_SEG
  93.      mov   ds,ax
  94.      rep   movsb             ;move the string into the buffer
  95. ;
  96. ;  Now, set up for the Netware Open Semaphore call
  97.      mov   ax,es             ;point back to the correct data segment
  98.      mov   ds,ax
  99.      mov   dx,OFFSET S_NAME_LEN
  100.      mov   cl,S_VALUE
  101. ;
  102. ;  Open the semaphore
  103.      mov   ax,0C500H         ; request Open Semaphore
  104.      int   21H
  105. ;
  106. ;  Check for completion code
  107.      cmp   al,0
  108.      JZ    open_ok
  109. ;
  110. ;  Error returned from Netware call - return error number
  111.      xor   bx,bx
  112.      mov   bl,al
  113.      jmp   INITEXIT
  114.  
  115. OPEN_OK:
  116. ;
  117. ;  Semaphore has been opened without error.  Save semaphore information
  118.      mov   S_HNDL_CX,cx
  119.      mov   S_HNDL_DX,dx
  120.      mov   NUM_STA,bl
  121.      xor   bx,bx             ; indicate correct operation
  122.  
  123. INITEXIT:
  124.      RET_INT  bx          ; return operation status
  125.      pop   dx
  126.      pop   cx
  127.      pop   bx
  128.      pop   ax
  129.      POPREGS
  130.      ret
  131.  
  132. INITCRIT ENDP
  133.  
  134.  
  135. CRITNUMS PROC     FAR
  136. ;
  137. ; Returns the number of stations having opened the semaphore
  138.      PUSHREGS
  139.      push  bx
  140.      xor   bx,bx
  141.      mov   bl,NUM_STA
  142.      RET_INT bx
  143.      pop   bx
  144.      POPREGS
  145.      ret
  146. CRITNUMS ENDP
  147.  
  148. STCRIT   PROC     FAR
  149. ;
  150. ; This procedure will allow us to check to see if we can enter a critical
  151. ; module without conflicting with others who want to use that module.
  152.      PUSHREGS
  153.      push  ax
  154.      push  cx
  155.      push  dx
  156.      push  bp
  157. ;
  158. ; Set up for Netware semaphore check
  159.      mov   cx,S_HNDL_CX      ; get the semaphore handle
  160.      mov   dx,S_HNDL_DX
  161.      mov   bp,180            ; ten second waiting period
  162.      mov   ax,0C502H         ; request Semaphore: Decrement and Wait if Negative
  163.      int   21H
  164.  
  165.      xor   ah,ah             ; clear AH - AL is return code
  166.      RET_INT ax
  167.      pop   bp
  168.      pop   dx
  169.      pop   cx
  170.      pop   ax
  171.      POPREGS
  172.      ret
  173. STCRIT   ENDP
  174.  
  175. ENDCRIT  PROC  FAR
  176. ;
  177. ; This procedure signals that we are finished with the critical module, and
  178. ; releases the semaphore for someone else's use
  179.      PUSHREGS
  180.      push  ax
  181.      push  cx
  182.      push  dx
  183. ;
  184. ; Set up for Netware semaphore release
  185.      mov   cx,S_HNDL_CX      ; semaphore handle
  186.      mov   dx,S_HNDL_DX
  187.      mov   ax,0C503H         ; request Semaphore: Increment and Release if Waiting
  188.      int   21H
  189.  
  190.      xor   ah,ah
  191.      RET_INT ax
  192.      pop   dx
  193.      pop   cx
  194.      pop   ax
  195.      POPREGS
  196.      ret
  197. ENDCRIT  ENDP
  198.  
  199. CLOSCRIT PROC     FAR
  200. ; releases a semaphore from use
  201.      PUSHREGS
  202.      push  ax
  203.      push  cx
  204.      push  dx
  205. ;
  206. ; Set up for Netware semaphore close
  207.      mov   cx,S_HNDL_CX      ; semaphore handle
  208.      mov   dx,S_HNDL_DX
  209.      mov   ax,0C504H         ; request Close Semaphore
  210.      INT   21H
  211.  
  212.      xor   ah,ah
  213.      RET_INT ax
  214.      pop   dx
  215.      pop   cx
  216.      pop   ax
  217.      POPREGS
  218.      ret
  219. CLOSCRIT ENDP
  220.  
  221. _PROG    ENDS
  222.  
  223.      END
  224.