home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / include / afxmt.h < prev    next >
C/C++ Source or Header  |  1998-06-16  |  5KB  |  252 lines

  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.  
  11. #ifndef __AFXMT_H__
  12. #define __AFXMT_H__
  13.  
  14. #ifndef __AFX_H__
  15.     #include <afx.h>
  16. #endif
  17.  
  18. #ifdef _AFX_MINREBUILD
  19. #pragma component(minrebuild, off)
  20. #endif
  21. #ifndef _AFX_FULLTYPEINFO
  22. #pragma component(mintypeinfo, on)
  23. #endif
  24.  
  25. #ifdef _AFX_PACKING
  26. #pragma pack(push, _AFX_PACKING)
  27. #endif
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // AFXMT - MFC Multithreaded Extensions (Syncronization Objects)
  31.  
  32. // Classes declared in this file
  33.  
  34. //CObject
  35.     class CSyncObject;
  36.         class CSemaphore;
  37.         class CMutex;
  38.         class CEvent;
  39.         class CCriticalSection;
  40.  
  41. class CSingleLock;
  42. class CMultiLock;
  43.  
  44. #undef AFX_DATA
  45. #define AFX_DATA AFX_CORE_DATA
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // Basic synchronization object
  49.  
  50. class CSyncObject : public CObject
  51. {
  52.     DECLARE_DYNAMIC(CSyncObject)
  53.  
  54. // Constructor
  55. public:
  56.     CSyncObject(LPCTSTR pstrName);
  57.  
  58. // Attributes
  59. public:
  60.     operator HANDLE() const;
  61.     HANDLE  m_hObject;
  62.  
  63. // Operations
  64.     virtual BOOL Lock(DWORD dwTimeout = INFINITE);
  65.     virtual BOOL Unlock() = 0;
  66.     virtual BOOL Unlock(LONG /* lCount */, LPLONG /* lpPrevCount=NULL */)
  67.         { return TRUE; }
  68.  
  69. // Implementation
  70. public:
  71.     virtual ~CSyncObject();
  72. #ifdef _DEBUG
  73.     CString m_strName;
  74.     virtual void AssertValid() const;
  75.     virtual void Dump(CDumpContext& dc) const;
  76. #endif
  77.     friend class CSingleLock;
  78.     friend class CMultiLock;
  79. };
  80.  
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CSemaphore
  83.  
  84. class CSemaphore : public CSyncObject
  85. {
  86.     DECLARE_DYNAMIC(CSemaphore)
  87.  
  88. // Constructor
  89. public:
  90.     CSemaphore(LONG lInitialCount = 1, LONG lMaxCount = 1,
  91.         LPCTSTR pstrName=NULL, LPSECURITY_ATTRIBUTES lpsaAttributes = NULL);
  92.  
  93. // Implementation
  94. public:
  95.     virtual ~CSemaphore();
  96.     virtual BOOL Unlock();
  97.     virtual BOOL Unlock(LONG lCount, LPLONG lprevCount = NULL);
  98. };
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CMutex
  102.  
  103. class CMutex : public CSyncObject
  104. {
  105.     DECLARE_DYNAMIC(CMutex)
  106.  
  107. // Constructor
  108. public:
  109.     CMutex(BOOL bInitiallyOwn = FALSE, LPCTSTR lpszName = NULL,
  110.         LPSECURITY_ATTRIBUTES lpsaAttribute = NULL);
  111.  
  112. // Implementation
  113. public:
  114.     virtual ~CMutex();
  115.     BOOL Unlock();
  116. };
  117.  
  118. /////////////////////////////////////////////////////////////////////////////
  119. // CEvent
  120.  
  121. class CEvent : public CSyncObject
  122. {
  123.     DECLARE_DYNAMIC(CEvent)
  124.  
  125. // Constructor
  126. public:
  127.     CEvent(BOOL bInitiallyOwn = FALSE, BOOL bManualReset = FALSE,
  128.         LPCTSTR lpszNAme = NULL, LPSECURITY_ATTRIBUTES lpsaAttribute = NULL);
  129.  
  130. // Operations
  131. public:
  132.     BOOL SetEvent();
  133.     BOOL PulseEvent();
  134.     BOOL ResetEvent();
  135.     BOOL Unlock();
  136.  
  137. // Implementation
  138. public:
  139.     virtual ~CEvent();
  140. };
  141.  
  142. /////////////////////////////////////////////////////////////////////////////
  143. // CCriticalSection
  144.  
  145. class CCriticalSection : public CSyncObject
  146. {
  147.     DECLARE_DYNAMIC(CCriticalSection)
  148.  
  149. // Constructor
  150. public:
  151.     CCriticalSection();
  152.  
  153. // Attributes
  154. public:
  155.     operator CRITICAL_SECTION*();
  156.     CRITICAL_SECTION m_sect;
  157.  
  158. // Operations
  159. public:
  160.     BOOL Unlock();
  161.     BOOL Lock();
  162.     BOOL Lock(DWORD dwTimeout);
  163.  
  164. // Implementation
  165. public:
  166.     virtual ~CCriticalSection();
  167. };
  168.  
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CSingleLock
  171.  
  172. class CSingleLock
  173. {
  174. // Constructors
  175. public:
  176.     CSingleLock(CSyncObject* pObject, BOOL bInitialLock = FALSE);
  177.  
  178. // Operations
  179. public:
  180.     BOOL Lock(DWORD dwTimeOut = INFINITE);
  181.     BOOL Unlock();
  182.     BOOL Unlock(LONG lCount, LPLONG lPrevCount = NULL);
  183.     BOOL IsLocked();
  184.  
  185. // Implementation
  186. public:
  187.     ~CSingleLock();
  188.  
  189. protected:
  190.     CSyncObject* m_pObject;
  191.     HANDLE  m_hObject;
  192.     BOOL    m_bAcquired;
  193. };
  194.  
  195. /////////////////////////////////////////////////////////////////////////////
  196. // CMultiLock
  197.  
  198. class CMultiLock
  199. {
  200. // Constructor
  201. public:
  202.     CMultiLock(CSyncObject* ppObjects[], DWORD dwCount, BOOL bInitialLock = FALSE);
  203.  
  204. // Operations
  205. public:
  206.     DWORD Lock(DWORD dwTimeOut = INFINITE, BOOL bWaitForAll = TRUE,
  207.         DWORD dwWakeMask = 0);
  208.     BOOL Unlock();
  209.     BOOL Unlock(LONG lCount, LPLONG lPrevCount = NULL);
  210.     BOOL IsLocked(DWORD dwItem);
  211.  
  212. // Implementation
  213. public:
  214.     ~CMultiLock();
  215.  
  216. protected:
  217.     HANDLE  m_hPreallocated[8];
  218.     BOOL    m_bPreallocated[8];
  219.  
  220.     CSyncObject* const * m_ppObjectArray;
  221.     HANDLE* m_pHandleArray;
  222.     BOOL*   m_bLockedArray;
  223.     DWORD   m_dwCount;
  224. };
  225.  
  226. /////////////////////////////////////////////////////////////////////////////
  227. // Inline function declarations
  228.  
  229. #ifdef _AFX_PACKING
  230. #pragma pack(pop)
  231. #endif
  232.  
  233. #ifdef _AFX_ENABLE_INLINES
  234. #define _AFXMT_INLINE AFX_INLINE
  235. #include <afxmt.inl>
  236. #undef _AFXMT_INLINE
  237. #endif
  238.  
  239. #undef AFX_DATA
  240. #define AFX_DATA
  241.  
  242. #ifdef _AFX_MINREBUILD
  243. #pragma component(minrebuild, on)
  244. #endif
  245. #ifndef _AFX_FULLTYPEINFO
  246. #pragma component(mintypeinfo, off)
  247. #endif
  248.  
  249. #endif  // __AFXMT_H__
  250.  
  251. /////////////////////////////////////////////////////////////////////////////
  252.