MySQL 8.4.2
Source Code Documentation
Thd_backup_and_restore Class Reference

Helper class to switch to a new thread and then go back to the previous one, when the object is destroyed using RAII. More...

Public Member Functions

 Thd_backup_and_restore (THD *backup_thd, THD *new_thd)
 Try to attach the POSIX thread to a session. More...
 
 ~Thd_backup_and_restore ()
 Restores to previous thd. More...
 

Private Attributes

THDm_backup_thd
 
THDm_new_thd
 
THDm_backup_cnt_thd
 
THDm_dummy_cnt_thd
 
my_thread_t m_new_thd_old_real_id
 
const char * m_new_thd_old_thread_stack
 

Detailed Description

Helper class to switch to a new thread and then go back to the previous one, when the object is destroyed using RAII.

This class is used to temporarily switch to another session (THD structure). It will set up thread specific "globals" correctly so that the POSIX thread looks exactly like the session attached to. However, PSI_thread info is not touched as it is required to show the actual physical view in PFS instrumentation i.e., it should depict as the real thread doing the work instead of thread it switched to.

On destruction, the original session (which is supplied to the constructor) will be re-attached automatically. For example, with this code, the value of current_thd will be the same before and after execution of the code.

{
for (int i = 0 ; i < count ; ++i)
{
// here we are attached to current_thd
// [...]
Thd_backup_and_restore switch_thd(current_thd, other_thd[i]);
// [...]
// here we are attached to other_thd[i]
// [...]
}
// here we are attached to current_thd
}
Helper class to switch to a new thread and then go back to the previous one, when the object is destr...
Definition: binlog.cc:640
thread_local THD * current_thd
Definition: current_thd.cc:26
static int count
Definition: myisam_ftdump.cc:45
Warning
The class is not designed to be inherited from.

Constructor & Destructor Documentation

◆ Thd_backup_and_restore()

Thd_backup_and_restore::Thd_backup_and_restore ( THD backup_thd,
THD new_thd 
)
inline

Try to attach the POSIX thread to a session.

Parameters
[in]backup_thdThe thd to restore to when object is destructed.
[in]new_thdThe thd to attach to.

◆ ~Thd_backup_and_restore()

Thd_backup_and_restore::~Thd_backup_and_restore ( )
inline

Restores to previous thd.

Member Data Documentation

◆ m_backup_cnt_thd

THD* Thd_backup_and_restore::m_backup_cnt_thd
private

◆ m_backup_thd

THD* Thd_backup_and_restore::m_backup_thd
private

◆ m_dummy_cnt_thd

THD* Thd_backup_and_restore::m_dummy_cnt_thd
private

◆ m_new_thd

THD* Thd_backup_and_restore::m_new_thd
private

◆ m_new_thd_old_real_id

my_thread_t Thd_backup_and_restore::m_new_thd_old_real_id
private

◆ m_new_thd_old_thread_stack

const char* Thd_backup_and_restore::m_new_thd_old_thread_stack
private

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