MCPcopy Create free account
hub / github.com/MariaDB/server / create_thd

Method create_thd

sql/sql_connect.cc:1607–1673  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1605/* Reuse or create a THD based on a CONNECT object */
1606
1607THD *CONNECT::create_thd(THD *thd)
1608{
1609 bool res, thd_reused= thd != 0;
1610 Vio *vio;
1611 DBUG_ENTER("create_thd");
1612
1613 DBUG_EXECUTE_IF("simulate_failed_connection_2", DBUG_RETURN(0); );
1614
1615 if (thd)
1616 {
1617 /* reuse old thd */
1618 thd->reset_for_reuse();
1619 /*
1620 reset tread_id's, but not thread_dbug_id's as the later isn't allowed
1621 to change as there is already structures in thd marked with the old
1622 value.
1623 */
1624 thd->thread_id= thd->variables.pseudo_thread_id= thread_id;
1625 }
1626 else if (!(thd= new THD(thread_id)))
1627 DBUG_RETURN(0);
1628
1629#if _WIN32
1630 if (vio_type == VIO_TYPE_NAMEDPIPE)
1631 vio= vio_new_win32pipe(pipe);
1632 else
1633#endif
1634 vio= mysql_socket_vio_new(sock, vio_type, vio_type == VIO_TYPE_SOCKET ?
1635 VIO_LOCALHOST : 0);
1636 if (!vio)
1637 {
1638 if (!thd_reused)
1639 delete thd;
1640 DBUG_RETURN(0);
1641 }
1642
1643 set_current_thd(thd);
1644 res= my_net_init(&thd->net, vio, thd, MYF(MY_THREAD_SPECIFIC));
1645 vio_type= VIO_CLOSED; // Vio now handled by thd
1646
1647 if (unlikely(res || thd->is_error()))
1648 {
1649 if (!thd_reused)
1650 delete thd;
1651 set_current_thd(0);
1652 DBUG_RETURN(0);
1653 }
1654
1655 init_net_server_extension(thd);
1656
1657 thd->security_ctx->host= thd->net.vio->type == VIO_TYPE_NAMEDPIPE ||
1658 thd->net.vio->type == VIO_TYPE_SOCKET ?
1659 my_localhost : 0;
1660
1661 thd->scheduler= scheduler;
1662 thd->real_id= pthread_self(); /* Duplicates THD::store_globals() setting. */
1663
1664 /* Attach PSI instrumentation to the new THD */

Callers 2

do_handle_one_connectionFunction · 0.80

Calls 8

vio_new_win32pipeFunction · 0.85
mysql_socket_vio_newFunction · 0.85
set_current_thdFunction · 0.85
my_net_initFunction · 0.85
reset_for_reuseMethod · 0.80
set_psiMethod · 0.80
is_errorMethod · 0.45

Tested by

no test coverage detected