Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
5.3 KiB

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #ifndef __AFXMT_H__
  11. #define __AFXMT_H__
  12. #ifndef __AFX_H__
  13. #include <afx.h>
  14. #endif
  15. #ifdef _AFX_MINREBUILD
  16. #pragma component(minrebuild, off)
  17. #endif
  18. #ifndef _AFX_FULLTYPEINFO
  19. #pragma component(mintypeinfo, on)
  20. #endif
  21. #ifdef _AFX_PACKING
  22. #pragma pack(push, _AFX_PACKING)
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // AFXMT - MFC Multithreaded Extensions (Syncronization Objects)
  26. // Classes declared in this file
  27. //CObject
  28. class CSyncObject;
  29. class CSemaphore;
  30. class CMutex;
  31. class CEvent;
  32. class CCriticalSection;
  33. class CSingleLock;
  34. class CMultiLock;
  35. #undef AFX_DATA
  36. #define AFX_DATA AFX_CORE_DATA
  37. /////////////////////////////////////////////////////////////////////////////
  38. // Basic synchronization object
  39. class CSyncObject : public CObject
  40. {
  41. DECLARE_DYNAMIC(CSyncObject)
  42. // Constructor
  43. public:
  44. CSyncObject(LPCTSTR pstrName);
  45. // Attributes
  46. public:
  47. operator HANDLE() const;
  48. HANDLE m_hObject;
  49. // Operations
  50. virtual BOOL Lock(DWORD dwTimeout = INFINITE);
  51. virtual BOOL Unlock() = 0;
  52. virtual BOOL Unlock(LONG /* lCount */, LPLONG /* lpPrevCount=NULL */)
  53. { return TRUE; }
  54. // Implementation
  55. public:
  56. virtual ~CSyncObject();
  57. #ifdef _DEBUG
  58. CString m_strName;
  59. virtual void AssertValid() const;
  60. virtual void Dump(CDumpContext& dc) const;
  61. #endif
  62. friend class CSingleLock;
  63. friend class CMultiLock;
  64. };
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CSemaphore
  67. class CSemaphore : public CSyncObject
  68. {
  69. DECLARE_DYNAMIC(CSemaphore)
  70. // Constructor
  71. public:
  72. CSemaphore(LONG lInitialCount = 1, LONG lMaxCount = 1,
  73. LPCTSTR pstrName=NULL, LPSECURITY_ATTRIBUTES lpsaAttributes = NULL);
  74. // Implementation
  75. public:
  76. virtual ~CSemaphore();
  77. virtual BOOL Unlock();
  78. virtual BOOL Unlock(LONG lCount, LPLONG lprevCount = NULL);
  79. };
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CMutex
  82. class CMutex : public CSyncObject
  83. {
  84. DECLARE_DYNAMIC(CMutex)
  85. // Constructor
  86. public:
  87. CMutex(BOOL bInitiallyOwn = FALSE, LPCTSTR lpszName = NULL,
  88. LPSECURITY_ATTRIBUTES lpsaAttribute = NULL);
  89. // Implementation
  90. public:
  91. virtual ~CMutex();
  92. BOOL Unlock();
  93. };
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CEvent
  96. class CEvent : public CSyncObject
  97. {
  98. DECLARE_DYNAMIC(CEvent)
  99. // Constructor
  100. public:
  101. CEvent(BOOL bInitiallyOwn = FALSE, BOOL bManualReset = FALSE,
  102. LPCTSTR lpszNAme = NULL, LPSECURITY_ATTRIBUTES lpsaAttribute = NULL);
  103. // Operations
  104. public:
  105. BOOL SetEvent();
  106. BOOL PulseEvent();
  107. BOOL ResetEvent();
  108. BOOL Unlock();
  109. // Implementation
  110. public:
  111. virtual ~CEvent();
  112. };
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CCriticalSection
  115. class CCriticalSection : public CSyncObject
  116. {
  117. DECLARE_DYNAMIC(CCriticalSection)
  118. // Constructor
  119. public:
  120. CCriticalSection();
  121. // Attributes
  122. public:
  123. operator CRITICAL_SECTION*();
  124. CRITICAL_SECTION m_sect;
  125. // Operations
  126. public:
  127. BOOL Unlock();
  128. BOOL Lock();
  129. BOOL Lock(DWORD dwTimeout);
  130. // Implementation
  131. public:
  132. virtual ~CCriticalSection();
  133. };
  134. /////////////////////////////////////////////////////////////////////////////
  135. // CSingleLock
  136. class CSingleLock
  137. {
  138. // Constructors
  139. public:
  140. CSingleLock(CSyncObject* pObject, BOOL bInitialLock = FALSE);
  141. // Operations
  142. public:
  143. BOOL Lock(DWORD dwTimeOut = INFINITE);
  144. BOOL Unlock();
  145. BOOL Unlock(LONG lCount, LPLONG lPrevCount = NULL);
  146. BOOL IsLocked();
  147. // Implementation
  148. public:
  149. ~CSingleLock();
  150. protected:
  151. CSyncObject* m_pObject;
  152. HANDLE m_hObject;
  153. BOOL m_bAcquired;
  154. };
  155. /////////////////////////////////////////////////////////////////////////////
  156. // CMultiLock
  157. class CMultiLock
  158. {
  159. // Constructor
  160. public:
  161. CMultiLock(CSyncObject* ppObjects[], DWORD dwCount, BOOL bInitialLock = FALSE);
  162. // Operations
  163. public:
  164. DWORD Lock(DWORD dwTimeOut = INFINITE, BOOL bWaitForAll = TRUE,
  165. DWORD dwWakeMask = 0);
  166. BOOL Unlock();
  167. BOOL Unlock(LONG lCount, LPLONG lPrevCount = NULL);
  168. BOOL IsLocked(DWORD dwItem);
  169. // Implementation
  170. public:
  171. ~CMultiLock();
  172. protected:
  173. HANDLE m_hPreallocated[8];
  174. BOOL m_bPreallocated[8];
  175. CSyncObject* const * m_ppObjectArray;
  176. HANDLE* m_pHandleArray;
  177. BOOL* m_bLockedArray;
  178. DWORD m_dwCount;
  179. };
  180. /////////////////////////////////////////////////////////////////////////////
  181. // Inline function declarations
  182. #ifdef _AFX_PACKING
  183. #pragma pack(pop)
  184. #endif
  185. #ifdef _AFX_ENABLE_INLINES
  186. #define _AFXMT_INLINE AFX_INLINE
  187. #include <afxmt.inl>
  188. #undef _AFXMT_INLINE
  189. #endif
  190. #undef AFX_DATA
  191. #define AFX_DATA
  192. #ifdef _AFX_MINREBUILD
  193. #pragma component(minrebuild, on)
  194. #endif
  195. #ifndef _AFX_FULLTYPEINFO
  196. #pragma component(mintypeinfo, off)
  197. #endif
  198. #endif // __AFXMT_H__
  199. /////////////////////////////////////////////////////////////////////////////