home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / sysembed / mutex.edh < prev    next >
Encoding:
Text File  |  1995-03-30  |  5.1 KB  |  165 lines

  1. [ 7. Mutual Exclusion Semaphores]
  2.                      EMBEDDED DOS MUTEX SEMAPHORES
  3. ════════════════════════════════════════════════════════════════════════
  4. The mutex object implements a mutual exclusion semaphore that is also
  5. MP-safe in multiprocessor systems.  Mutex objects are allocated and
  6. deallocated in the same way that events are.  They are acquired and
  7. released as needed to guard a critical section.  A mutex is assigned
  8. a state, and must always be in either the acquired or released states.
  9.  
  10. Mutexes may be used to control exclusive access to any object that they
  11. are associated with.  For example, the disk BIOS may be assigned a mutex
  12. that disallows more than one request at a time from being submitted to
  13. the BIOS.  Similarly, a mutex can be used to guard a software object,
  14. such as a data structure.
  15.  
  16. Mutexes should not be acquired at interrupt time, because an interrupt
  17. occurs during the context of some arbitrary thread.  To acquire a mutex
  18. in response to an interrupt, a secondary thread may be created or
  19. unblocked on the fly at interrupt time so as to define a thread that
  20. can acquire the mutex and perform the guarded work.
  21.  
  22. 1.  AllocateMutex
  23.  
  24. A mutex object is created with the AllocateMutex kernel function.
  25. Once the mutex is allocated, it is automatically maintained by
  26. the kernel in response to service requests.
  27.  
  28. This function returns a handle to a mutex object that must be used
  29. by the caller in subsequent kernel services that operate on mutexes.
  30. The kernel initializes the mutex object to the released state.
  31.  
  32. Upon return, the macro instruction call clears the carry flag if
  33. the operation was successful, and sets it if the operation was
  34. not performed.
  35.  
  36. Assembly Language Format:
  37.  
  38.      mov  dl, SYS_ALLOCATE_MUTEX
  39.      int  2dh                   ; (AX) = handle to mutex.
  40.      jc   Failure
  41.  
  42. Macro Instruction Format:
  43.  
  44. label     AllocateMutex  <MutexHandle>
  45.  
  46. Portable Request Format:
  47.  
  48. STATUS AllocateMutex(
  49.      OUT PHANDLE MutexHandle
  50.      );
  51.  
  52. Parameters:
  53.  
  54.      MutexHandle - Specifies a 16-bit general purpose register or
  55.           a pointer to a word in memory where the kernel will
  56.           return a handle to the allocated mutex.
  57.  
  58. 2.  DeallocateMutex
  59.  
  60. A mutex object is destroyed with the DeallocateMutex kernel
  61. function.  Once the mutex is deallocated, it is no longer
  62. available to the caller, and the handle becomes invalid.
  63.  
  64. If a mutex is deallocated that has one or more threads still
  65. blocked trying to acquire it, those threads are automatically
  66. destroyed by the kernel.
  67.  
  68. Upon return, the macro instruction call clears the carry flag if
  69. the operation was successful, and sets it if the operation was
  70. not performed.
  71.  
  72. Assembly Language Format:
  73.  
  74.      mov  ax, <MutexHandle>     ; (AX) = mutex handle.
  75.      mov  dl, SYS_DEALLOCATE_MUTEX
  76.      int  2dh
  77.      jc   Failure
  78.  
  79. Macro Instruction Format:
  80.  
  81. label     DeallocateMutex     <MutexHandle>
  82.  
  83. Portable Request Format:
  84.  
  85. STATUS DeallocateMutex(
  86.      IN HANDLE MutexHandle
  87.      );
  88.  
  89. Parameters:
  90.  
  91.      MutexHandle - Specifies a 16-bit general purpose register or
  92.           a word in memory containing a handle to the mutex to be
  93.           deallocated.
  94.  
  95. 3.  AcquireMutex
  96.  
  97. A mutex object is set to the acquired state with the AcquireMutex
  98. kernel function.  Once the mutex is acquired, other threads will
  99. block on any further attempts to acquire the mutex until the
  100. first thread releases the mutex.
  101.  
  102. Upon return, the macro instruction call clears the carry flag if
  103. the operation was successful, and sets it if the operation was
  104. not performed.
  105.  
  106. Assembly Language Format:
  107.  
  108.      mov  ax, <MutexHandle>     ; (AX) = mutex handle.
  109.      mov  dl, SYS_ACQUIRE_MUTEX
  110.      int  2dh
  111.      jc   Failure
  112.  
  113. Macro Instruction Format:
  114.  
  115. label     AcquireMutex   <MutexHandle>
  116.  
  117. Portable Request Format:
  118.  
  119. STATUS AcquireMutex(
  120.      IN HANDLE MutexHandle
  121.      );
  122.  
  123. Parameters:
  124.  
  125.      MutexHandle - Specifies a 16-bit general purpose register or
  126.           a word in memory containing a handle to the mutex to be
  127.           acquired.
  128.  
  129. 4.  ReleaseMutex
  130.  
  131. A mutex object is set to the released state with the ReleaseMutex
  132. kernel function.  Once the mutex is released, the kernel returns
  133. to the caller.  Additionally, if there is at least one thread
  134. blocked on the mutex waiting to acquire it, then the kernel
  135. leaves the mutex in the acquired state and unblocks the next
  136. thread waiting to acquire it.  If there are no other threads
  137. waiting to acquire the mutex, then the kernel resets it to the
  138. released state.
  139.  
  140. Upon return, the macro instruction call clears the carry flag if
  141. the operation was successful, and sets it if the operation was
  142. not performed.
  143.  
  144. Assembly Language Format:
  145.  
  146.      mov  ax, <MutexHandle>     ; (AX) = handle to mutex.
  147.      mov  dl, SYS_RELEASE_MUTEX
  148.      int  2dh
  149.      jc   Failure
  150.  
  151. Macro Instruction Format:
  152.  
  153. label     ReleaseMutex   <MutexHandle>
  154.  
  155. Portable Request Format:
  156.  
  157. STATUS ReleaseMutex(
  158.      IN HANDLE MutexHandle
  159.      );
  160.  
  161. Parameters:
  162.  
  163.      MutexHandle - Specifies a 16-bit general purpose register or
  164.           a word in memory containing a handle to the mutex to be
  165.           released.