MySQL 8.4.0
Source Code Documentation
THD_instance_guard Class Reference

Sentry class for managing the need to create and dispose of a local THD instance. More...

#include <rpl_utility.h>

Public Member Functions

 THD_instance_guard (THD *thd)
 If the given THD object pointer is nullptr, a new instance will be initialized within the constructor and disposed of in the destructor. More...
 
virtual ~THD_instance_guard ()
 If a new instance of THD was created in the constructor, it will be disposed here. More...
 
 operator THD * ()
 Returns the active THD object pointer. More...
 

Private Attributes

THDm_target {nullptr}
 The active THD object pointer. More...
 
bool m_is_locally_initialized {false}
 Tells whether or not the active THD object was created in this object constructor. More...
 

Detailed Description

Sentry class for managing the need to create and dispose of a local THD instance.

If the given THD object pointer passed on the constructor is nullptr, a new instance will be initialized within the constructor and disposed of in the destructor.

If the given THD object pointer passed on the constructor is not nullptr, the reference is kept and nothing is disposed on the destructor.

Casting operator to THD* is also provided, to easy code replacemente.

Usage example:

 THD_instance_guard thd{current_thd != nullptr ? current_thd :
                                                 this->info_thd};
 Acl_cache_lock_guard guard{thd, Acl_cache_lock_mode::READ_MODE};
 if (guard.lock())
   ...

Constructor & Destructor Documentation

◆ THD_instance_guard()

THD_instance_guard::THD_instance_guard ( THD thd)

If the given THD object pointer is nullptr, a new instance will be initialized within the constructor and disposed of in the destructor.

If the given THD object pointer is not nullptr, the reference is kept and nothing is disposed on the destructor.

Parameters
thdTHD object reference that determines if an existence instance is used or a new instance of THD must be created.

◆ ~THD_instance_guard()

THD_instance_guard::~THD_instance_guard ( )
virtual

If a new instance of THD was created in the constructor, it will be disposed here.

Member Function Documentation

◆ operator THD *()

THD_instance_guard::operator THD * ( )

Returns the active THD object pointer.

Returns
a not-nullptr THD object pointer.

Member Data Documentation

◆ m_is_locally_initialized

bool THD_instance_guard::m_is_locally_initialized {false}
private

Tells whether or not the active THD object was created in this object constructor.

◆ m_target

THD* THD_instance_guard::m_target {nullptr}
private

The active THD object pointer.


The documentation for this class was generated from the following files: