CComSafeDeleteCriticalSection Class
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at CComSafeDeleteCriticalSection Class.
This class provides methods for obtaining and releasing ownership of a critical section object.
class CComSafeDeleteCriticalSection : public CComCriticalSection
Public Constructors
| Name | Description |
|---|---|
| CComSafeDeleteCriticalSection::CComSafeDeleteCriticalSection | The constructor. |
| CComSafeDeleteCriticalSection::~CComSafeDeleteCriticalSection | The destructor. |
Public Methods
| Name | Description |
|---|---|
| CComSafeDeleteCriticalSection::Init | Creates and initializes a critical section object. |
| CComSafeDeleteCriticalSection::Lock | Obtains ownership of the critical section object. |
| CComSafeDeleteCriticalSection::Term | Releases system resources used by the critical section object. |
Data Members
| m_bInitialized | Flags whether the internal CRITICAL_SECTION object has been initialized. |
CComSafeDeleteCriticalSection derives from the class CComCriticalSection. However, CComSafeDeleteCriticalSection provides additional safety mechanisms over CComCriticalSection.
When an instance of CComSafeDeleteCriticalSection goes out of scope or is explicitly deleted from memory, the underlying critical section object will automatically be cleaned up if it is still valid. In addition, the CComSafeDeleteCriticalSection::Term method will exit gracefully if the underlying critical section object has not yet been allocated or has already been released from memory.
See CComCriticalSection for more information on critical section helper classes.
CComSafeDeleteCriticalSection
Header: atlcore.h
The constructor.
CComSafeDeleteCriticalSection();
Remarks
Sets the m_bInitialized data member to false.
The destructor.
~CComSafeDeleteCriticalSection() throw();
Remarks
Releases the internal CRITICAL_SECTION object from memory if the m_bInitialized data member is set to true.
Calls the base class implementation of Init and sets m_bInitialized to true if successful.
HRESULT Init() throw();
Return Value
Returns the result of CComCriticalSection::Init.
Calls the base class implementation of Lock.
HRESULT Lock();
Return Value
Returns the result of CComCriticalSection::Lock.
Remarks
This method assumes the m_bInitialized data member is set to true upon entry. An assertion is generated in Debug builds if this condidtion is not met.
For more information on the behavior of the function, refer to CComCriticalSection::Lock.
Flags whether the internal CRITICAL_SECTION object has been initialized.
bool m_bInitialized;
Remarks
The m_bInitialized data member is used to track validity of the underlying CRITICAL_SECTION object associated with the CComSafeDeleteCriticalSection class. The underlying CRITICAL_SECTION object will not be attempted to be released from memory if this flag is not set to true.
Calls the base class implementation of CComCriticalSection::Term if the internal CRITICAL_SECTION object is valid.
HRESULT Term() throw();
Return Value
Returns the result of CComCriticalSection::Term, or S_OK if m_bInitialized was set to false upon entry.
Remarks
It is safe to call this method even if the internal CRITICAL_SECTION object is not valid. The destructor of this class calls this method if the m_bInitialized data member is set to true.