Edit

Share via


CComSafeDeleteCriticalSection Class

This class provides methods for obtaining and releasing ownership of a critical section object.

Syntax

class CComSafeDeleteCriticalSection : public CComCriticalSection

Members

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

Data member Description
m_bInitialized Flags whether the internal CRITICAL_SECTION object has been initialized.

Remarks

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.

Inheritance Hierarchy

CComCriticalSection

CComSafeDeleteCriticalSection

Requirements

Header: atlcore.h

CComSafeDeleteCriticalSection::CComSafeDeleteCriticalSection

The constructor.

CComSafeDeleteCriticalSection();

Remarks

Sets the m_bInitialized data member to FALSE.

CComSafeDeleteCriticalSection::~CComSafeDeleteCriticalSection

The destructor.

~CComSafeDeleteCriticalSection() throw();

Remarks

Releases the internal CRITICAL_SECTION object from memory if the m_bInitialized data member is set to TRUE.

CComSafeDeleteCriticalSection::Init

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.

CComSafeDeleteCriticalSection::Lock

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 condition is not met.

For more information on the behavior of the function, refer to CComCriticalSection::Lock.

CComSafeDeleteCriticalSection::m_bInitialized

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.

CComSafeDeleteCriticalSection::Term

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.

See also

CComCriticalSection Class
Class Overview