Create a THD that only has auxiliary functions It will never be added to the global connection list server_threads. It does not represent any client connection. It should never be counted, because it will stall the shutdown. It is solely for engine's internal use, like for example, evaluation of virtual function in innodb purge. */
| 5477 | purge. |
| 5478 | */ |
| 5479 | MYSQL_THD create_background_thd() |
| 5480 | { |
| 5481 | THD *save_thd= current_thd; |
| 5482 | set_current_thd(nullptr); |
| 5483 | |
| 5484 | auto save_mysysvar= my_thread_var; |
| 5485 | |
| 5486 | /* |
| 5487 | Allocate new mysys_var specifically new THD, |
| 5488 | so that e.g safemalloc, DBUG etc are happy. |
| 5489 | */ |
| 5490 | set_mysys_var(nullptr); |
| 5491 | my_thread_init(); |
| 5492 | auto thd_mysysvar= my_thread_var; |
| 5493 | auto thd= new THD(0); |
| 5494 | set_mysys_var(save_mysysvar); |
| 5495 | thd->set_psi(nullptr); |
| 5496 | set_current_thd(save_thd); |
| 5497 | |
| 5498 | /* |
| 5499 | Workaround the adverse effect of incrementing thread_count |
| 5500 | in THD constructor. We do not want these THDs to be counted, |
| 5501 | or waited for on shutdown. |
| 5502 | */ |
| 5503 | THD_count::count--; |
| 5504 | |
| 5505 | thd->mysys_var= (st_my_thread_var *) thd_mysysvar; |
| 5506 | thd->set_command(COM_DAEMON); |
| 5507 | thd->system_thread= SYSTEM_THREAD_GENERIC; |
| 5508 | thd->security_ctx->host_or_ip= ""; |
| 5509 | thd->real_id= 0; |
| 5510 | thd->thread_id= 0; |
| 5511 | thd->query_id= 0; |
| 5512 | #ifdef WITH_WSREP |
| 5513 | thd->variables.wsrep_on= FALSE; |
| 5514 | #endif /* WITH_WSREP */ |
| 5515 | return thd; |
| 5516 | } |
| 5517 | |
| 5518 | |
| 5519 | /* |
no test coverage detected