| 292 | |
| 293 | |
| 294 | static THD *threadpool_add_connection(CONNECT *connect, TP_connection *c) |
| 295 | { |
| 296 | THD *thd= NULL; |
| 297 | |
| 298 | /* |
| 299 | Create a new connection context: mysys_thread_var and PSI thread |
| 300 | Store them in THD. |
| 301 | */ |
| 302 | |
| 303 | set_mysys_var(NULL); |
| 304 | my_thread_init(); |
| 305 | st_my_thread_var* mysys_var= my_thread_var; |
| 306 | PSI_CALL_set_thread(PSI_CALL_new_thread(key_thread_one_connection, connect, 0)); |
| 307 | if (!mysys_var ||!(thd= connect->create_thd(NULL))) |
| 308 | { |
| 309 | /* Out of memory? */ |
| 310 | connect->close_and_delete(0); |
| 311 | if (mysys_var) |
| 312 | my_thread_end(); |
| 313 | return NULL; |
| 314 | } |
| 315 | |
| 316 | thd->event_scheduler.data= c; |
| 317 | server_threads.insert(thd); // Make THD visible in show processlist |
| 318 | delete connect; // must be after server_threads.insert, see close_connections() |
| 319 | thd->set_mysys_var(mysys_var); |
| 320 | |
| 321 | /* Login. */ |
| 322 | thread_attach(thd); |
| 323 | mysql_socket_set_thread_owner(thd->net.vio->mysql_socket); |
| 324 | re_init_net_server_extension(thd); |
| 325 | ulonglong now= microsecond_interval_timer(); |
| 326 | thd->prior_thr_create_utime= now; |
| 327 | thd->start_utime= now; |
| 328 | thd->thr_create_utime= now; |
| 329 | |
| 330 | setup_connection_thread_globals(thd); |
| 331 | |
| 332 | if (thd_prepare_connection(thd)) |
| 333 | goto end; |
| 334 | |
| 335 | c->init_vio(thd->net.vio); |
| 336 | |
| 337 | /* |
| 338 | Check if THD is ok, as prepare_new_connection_state() |
| 339 | can fail, for example if init command failed. |
| 340 | */ |
| 341 | if (!thd_is_connection_alive(thd)) |
| 342 | goto end; |
| 343 | |
| 344 | thd->skip_wait_timeout= true; |
| 345 | set_thd_idle(thd); |
| 346 | return thd; |
| 347 | |
| 348 | end: |
| 349 | threadpool_remove_connection(thd); |
| 350 | return NULL; |
| 351 | } |
no test coverage detected