home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vdmutils.zip / MUTEXSEM.ASM < prev    next >
Assembly Source File  |  1997-10-18  |  6KB  |  154 lines

  1. ; Subroutine to manipulate mutex semaphores from a VDM.
  2. ; Copyright (C) 1996, David W. Noon
  3.            .286
  4.            .287
  5. ;          OPTION   CASEMAP:ALL
  6.            ASSUME   CS:_TEXT
  7. _TEXT      SEGMENT  PARA READONLY PUBLIC USE16 'CODE'
  8. ; Create a mutex semaphore.
  9.            PUBLIC   DWNCREATEMUTEXSEM
  10. DWNCREATEMUTEXSEM PROC FAR PASCAL
  11.            PUSH     BP          ; Stack housekeeping
  12.            MOV      BP,SP       ;
  13.  
  14.            PUSH     DS          ; Save working ...
  15.            PUSH     SI          ; ... registers.
  16.            PUSH     ES          ; ...
  17.            PUSH     DI          ; ...
  18.  
  19.            MOV      AH,64H              ;  Set up the parameter list:
  20.            MOV      CX,636CH            ;     Magic number - see docs.
  21.            MOV      BX,014BH            ;     Indicator for create mutex sem.
  22.            LES      DI,DWORD PTR 14[BP] ;     Address of semaphore name
  23.            LDS      SI,DWORD PTR 10[BP] ;     Address of semaphore handle (HMTX)
  24.            MOV      DX,WORD PTR 8[BP]   ;     Attributes (1 = DC_SEM_SHARED)
  25.            MOV      AL,BYTE PTR 6[BP]   ;     State (1 = owned)
  26.  
  27.            INT      21H         ; Issue the multiplex interrupt
  28.            JC       SHORT $+4   ; Skip clearing AX if carry
  29.            XOR      AX,AX       ; Return code zero if no error
  30.  
  31.            POP      DI          ; Restore working ...
  32.            POP      ES          ; ... registers.
  33.            POP      SI          ; ...
  34.            POP      DS          ; ...
  35.  
  36.            MOV      SP,BP       ; Restore stack
  37.            POP      BP          ;
  38.  
  39.            RETF     12          ; Clean up 12 bytes of parameter pointers
  40. DWNCREATEMUTEXSEM ENDP
  41.            ALIGN    10H
  42. ; Open a mutex semaphore.
  43.            PUBLIC   DWNOPENMUTEXSEM
  44. DWNOPENMUTEXSEM PROC FAR PASCAL
  45.            PUSH     BP          ; Stack housekeeping
  46.            MOV      BP,SP       ;
  47.  
  48.            PUSH     DS          ; Save working ...
  49.            PUSH     SI          ; ... registers.
  50.            PUSH     ES          ; ...
  51.            PUSH     DI          ; ...
  52.  
  53.            MOV      AH,64H              ;  Set up the parameter list:
  54.            MOV      CX,636CH            ;     Magic number - see docs.
  55.            MOV      BX,014CH            ;     Indicator for open mutex sem.
  56.            LES      DI,DWORD PTR 10[BP] ;     Address of semaphore name
  57.            LDS      SI,DWORD PTR 6[BP]  ;     Address of semaphore handle (HMTX)
  58.  
  59.            INT      21H         ; Issue the multiplex interrupt
  60.            JC       SHORT $+4   ; Skip clearing AX if carry
  61.            XOR      AX,AX       ; Return code zero if no error
  62.  
  63.            POP      DI          ; Restore working ...
  64.            POP      ES          ; ... registers.
  65.            POP      SI          ; ...
  66.            POP      DS          ; ...
  67.  
  68.            MOV      SP,BP       ; Restore stack
  69.            POP      BP          ;
  70.  
  71.            RETF     8           ; Clean up 8 bytes of parameter pointers
  72. DWNOPENMUTEXSEM ENDP
  73.            ALIGN    10H
  74. ; Close a mutex semaphore.
  75.            PUBLIC   DWNCLOSEMUTEXSEM
  76. DWNCLOSEMUTEXSEM PROC FAR PASCAL
  77.            PUSH     BP          ; Stack housekeeping
  78.            MOV      BP,SP       ;
  79.  
  80.            PUSH     SI          ; Save working register.
  81.  
  82.            MOV      AH,64H            ;  Set up the parameter list:
  83.            MOV      CX,636CH          ;     Magic number - see docs.
  84.            MOV      BX,014DH          ;     Indicator for close mutex sem.
  85.            MOV      SI,WORD PTR 6[BP] ;     Semaphore handle (HMTX)
  86.            MOV      DX,WORD PTR 8[BP] ;       into DX:SI
  87.  
  88.            INT      21H         ; Issue the multiplex interrupt
  89.            JC       SHORT $+4   ; Skip clearing AX if carry
  90.            XOR      AX,AX       ; Return code zero if no error
  91.  
  92.            POP      SI          ; Restore working register.
  93.  
  94.            MOV      SP,BP       ; Restore stack
  95.            POP      BP          ;
  96.  
  97.            RETF     4           ; Clean up 4 bytes of parameter
  98. DWNCLOSEMUTEXSEM ENDP
  99.            ALIGN    10H
  100. ; Request a mutex semaphore.
  101.            PUBLIC   DWNREQUESTMUTEXSEM
  102. DWNREQUESTMUTEXSEM PROC FAR PASCAL
  103.            PUSH     BP          ; Stack housekeeping
  104.            MOV      BP,SP       ;
  105.  
  106.            PUSH     SI          ; Save working register.
  107.  
  108.            MOV      AH,64H             ;  Set up the parameter list:
  109.            MOV      CX,636CH           ;     Magic number - see docs.
  110.            MOV      BX,014EH           ;     Indicator for request mutex sem.
  111.            MOV      SI,WORD PTR 10[BP] ;     Semaphore handle (HMTX)
  112.            MOV      DX,WORD PTR 12[BP] ;       into DX:SI
  113.            MOV      AL,BYTE PTR 6[BP]  ;     Timeout value (was a long!)
  114.  
  115.            INT      21H         ; Issue the multiplex interrupt
  116.            JC       SHORT $+4   ; Skip clearing AX if carry
  117.            XOR      AX,AX       ; Return code zero if no error
  118.  
  119.            POP      SI          ; Restore working register.
  120.  
  121.            MOV      SP,BP       ; Restore stack
  122.            POP      BP          ;
  123.  
  124.            RETF     8           ; Clean up 8 bytes of parameter
  125. DWNREQUESTMUTEXSEM ENDP
  126.            ALIGN    10H
  127. ; Release a mutex semaphore.
  128.            PUBLIC   DWNRELEASEMUTEXSEM
  129. DWNRELEASEMUTEXSEM PROC FAR PASCAL
  130.            PUSH     BP          ; Stack housekeeping
  131.            MOV      BP,SP       ;
  132.  
  133.            PUSH     SI          ; Save working register.
  134.  
  135.            MOV      AH,64H            ;  Set up the parameter list:
  136.            MOV      CX,636CH          ;     Magic number - see docs.
  137.            MOV      BX,014FH          ;     Indicator for release mutex sem.
  138.            MOV      SI,WORD PTR 6[BP] ;     Semaphore handle (HMTX)
  139.            MOV      DX,WORD PTR 8[BP] ;       into DX:SI
  140.  
  141.            INT      21H         ; Issue the multiplex interrupt
  142.            JC       SHORT $+4   ; Skip clearing AX if carry
  143.            XOR      AX,AX       ; Return code zero if no error
  144.  
  145.            POP      SI          ; Restore working register.
  146.  
  147.            MOV      SP,BP       ; Restore stack
  148.            POP      BP          ;
  149.  
  150.            RETF     4           ; Clean up 4 bytes of parameter
  151. DWNRELEASEMUTEXSEM ENDP
  152. _TEXT      ENDS
  153.            END
  154.