Source code of Windows XP (NT5)
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.

136 lines
3.6 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-2001 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10. #ifndef __ATLSYNC_H__
  11. #define __ATLSYNC_H__
  12. #pragma once
  13. #ifndef _ATL_NO_PRAGMA_WARNINGS
  14. #pragma warning(push)
  15. #pragma warning(disable: 4512) // assignment operator could not be generated
  16. #endif // !_ATL_NO_PRAGMA_WARNINGS
  17. #include <atlbase.h>
  18. namespace ATL
  19. {
  20. class CCriticalSection :
  21. public CRITICAL_SECTION
  22. {
  23. public:
  24. CCriticalSection();
  25. #if (_WIN32_WINNT >= 0x0403)
  26. explicit CCriticalSection( ULONG nSpinCount );
  27. #endif
  28. ~CCriticalSection() throw();
  29. // Acquire the critical section
  30. void Enter();
  31. // Release the critical section
  32. void Leave() throw();
  33. #if (_WIN32_WINNT >= 0x0403)
  34. // Set the spin count for the critical section
  35. ULONG SetSpinCount( ULONG nSpinCount ) throw();
  36. #endif
  37. #if (_WIN32_WINNT >= 0x0400)
  38. // Attempt to acquire the critical section
  39. BOOL TryEnter() throw();
  40. #endif
  41. };
  42. class CEvent :
  43. public CHandle
  44. {
  45. public:
  46. CEvent() throw();
  47. CEvent( CEvent& h ) throw();
  48. CEvent( BOOL bManualReset, BOOL bInitialState );
  49. CEvent( LPSECURITY_ATTRIBUTES pSecurity, BOOL bManualReset, BOOL bInitialState, LPCTSTR pszName );
  50. explicit CEvent( HANDLE h ) throw();
  51. // Create a new event
  52. BOOL Create( LPSECURITY_ATTRIBUTES pSecurity, BOOL bManualReset, BOOL bInitialState, LPCTSTR pszName ) throw();
  53. // Open an existing named event
  54. BOOL Open( DWORD dwAccess, BOOL bInheritHandle, LPCTSTR pszName ) throw();
  55. // Pulse the event (signals waiting objects, then resets)
  56. BOOL Pulse() throw();
  57. // Set the event to the non-signaled state
  58. BOOL Reset() throw();
  59. // Set the event to the signaled state
  60. BOOL Set() throw();
  61. };
  62. class CMutex :
  63. public CHandle
  64. {
  65. public:
  66. CMutex() throw();
  67. CMutex( CMutex& h ) throw();
  68. explicit CMutex( BOOL bInitialOwner );
  69. CMutex( LPSECURITY_ATTRIBUTES pSecurity, BOOL bInitialOwner, LPCTSTR pszName );
  70. explicit CMutex( HANDLE h ) throw();
  71. // Create a new mutex
  72. BOOL Create( LPSECURITY_ATTRIBUTES pSecurity, BOOL bInitialOwner, LPCTSTR pszName ) throw();
  73. // Open an existing named mutex
  74. BOOL Open( DWORD dwAccess, BOOL bInheritHandle, LPCTSTR pszName ) throw();
  75. // Release ownership of the mutex
  76. BOOL Release() throw();
  77. };
  78. class CSemaphore :
  79. public CHandle
  80. {
  81. public:
  82. CSemaphore() throw();
  83. CSemaphore( CSemaphore& h ) throw();
  84. CSemaphore( LONG nInitialCount, LONG nMaxCount );
  85. CSemaphore( LPSECURITY_ATTRIBUTES pSecurity, LONG nInitialCount, LONG nMaxCount, LPCTSTR pszName );
  86. explicit CSemaphore( HANDLE h ) throw();
  87. // Create a new semaphore
  88. BOOL Create( LPSECURITY_ATTRIBUTES pSecurity, LONG nInitialCount, LONG nMaxCount, LPCTSTR pszName ) throw();
  89. // Open an existing named semaphore
  90. BOOL Open( DWORD dwAccess, BOOL bInheritHandle, LPCTSTR pszName ) throw();
  91. // Increase the count of the semaphore
  92. BOOL Release( LONG nReleaseCount = 1, LONG* pnOldCount = NULL ) throw();
  93. };
  94. class CMutexLock
  95. {
  96. public:
  97. CMutexLock( CMutex& mtx, bool bInitialLock = true );
  98. ~CMutexLock() throw();
  99. void Lock();
  100. void Unlock() throw();
  101. // Implementation
  102. private:
  103. CMutex& m_mtx;
  104. bool m_bLocked;
  105. // Private to prevent accidental use
  106. CMutexLock( const CMutexLock& ) throw();
  107. CMutexLock& operator=( const CMutexLock& ) throw();
  108. };
  109. }; // namespace ATL
  110. #include <atlsync.inl>
  111. #ifndef _ATL_NO_PRAGMA_WARNINGS
  112. #pragma warning(pop)
  113. #endif // !_ATL_NO_PRAGMA_WARNINGS
  114. #endif // __ATLSYNC_H__