diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc index fdca2c47dbc..2fc2e00d043 100644 --- a/sql/debug_sync.cc +++ b/sql/debug_sync.cc @@ -287,12 +287,6 @@ void debug_sync_end_thread(THD *thd) { st_debug_sync_control *ds_control= thd->debug_sync_control; - /* - This synchronization point can be used to synchronize on thread end. - This is the latest point in a THD's life, where this can be done. - */ - DEBUG_SYNC(thd, "thread_end"); - if (ds_control->ds_action) { st_debug_sync_action *action= ds_control->ds_action; @@ -322,6 +316,20 @@ void debug_sync_end_thread(THD *thd) } +void debug_sync_reset_thread(THD *thd) +{ + if (thd->debug_sync_control) + { + /* + This synchronization point can be used to synchronize on thread end. + This is the latest point in a THD's life, where this can be done. + */ + DEBUG_SYNC(thd, "thread_end"); + thd->debug_sync_control->ds_active= 0; + } +} + + /** Move a string by length. diff --git a/sql/debug_sync.h b/sql/debug_sync.h index 7a63a52959c..d92dc48cb0a 100644 --- a/sql/debug_sync.h +++ b/sql/debug_sync.h @@ -41,10 +41,14 @@ extern int debug_sync_init(void); extern void debug_sync_end(void); extern void debug_sync_init_thread(THD *thd); extern void debug_sync_end_thread(THD *thd); +void debug_sync_reset_thread(THD *thd); extern bool debug_sync_set_action(THD *thd, const char *action_str, size_t len); extern bool debug_sync_update(THD *thd, char *val_str, size_t len); extern uchar *debug_sync_value_ptr(THD *thd); - +#else +static inline void debug_sync_init_thread(THD *thd) {} +static inline void debug_sync_end_thread(THD *thd) {} +static inline void debug_sync_reset_thread(THD *thd) {} #endif /* defined(ENABLED_DEBUG_SYNC) */ #endif /* DEBUG_SYNC_INCLUDED */ diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 2143a9d4008..f7a42481082 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -840,6 +840,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) reset_open_tables_state(this); init(); + debug_sync_init_thread(this); #if defined(ENABLED_PROFILING) profiling.set_thd(this); #endif @@ -1320,11 +1321,6 @@ void THD::init() /* Set to handle counting of aborted connections */ userstat_running= opt_userstat_running; last_global_update_time= current_connect_time= time(NULL); -#if defined(ENABLED_DEBUG_SYNC) - /* Initialize the Debug Sync Facility. See debug_sync.cc. */ - debug_sync_init_thread(this); -#endif /* defined(ENABLED_DEBUG_SYNC) */ - #ifndef EMBEDDED_LIBRARY session_tracker.enable(this); #endif //EMBEDDED_LIBRARY @@ -1576,11 +1572,6 @@ void THD::cleanup(void) } wt_thd_destroy(&transaction.wt); -#if defined(ENABLED_DEBUG_SYNC) - /* End the Debug Sync Facility. See debug_sync.cc. */ - debug_sync_end_thread(this); -#endif /* defined(ENABLED_DEBUG_SYNC) */ - my_hash_free(&user_vars); my_hash_free(&sequences); sp_cache_clear(&sp_proc_cache); @@ -1634,6 +1625,7 @@ void THD::free_connection() #if defined(ENABLED_PROFILING) profiling.restart(); // Reset profiling #endif + debug_sync_reset_thread(this); } /* @@ -1742,6 +1734,7 @@ THD::~THD() lf_hash_put_pins(tdc_hash_pins); if (xid_hash_pins) lf_hash_put_pins(xid_hash_pins); + debug_sync_end_thread(this); /* Ensure everything is freed */ status_var.local_memory_used-= sizeof(THD);