| 342 | */ |
| 343 | |
| 344 | void tc_add_table(THD *thd, TABLE *table) |
| 345 | { |
| 346 | uint32_t i= |
| 347 | thd->thread_id % tc_active_instances.load(std::memory_order_relaxed); |
| 348 | TABLE *LRU_table= 0; |
| 349 | TDC_element *element= table->s->tdc; |
| 350 | |
| 351 | DBUG_ASSERT(table->in_use == thd); |
| 352 | table->instance= i; |
| 353 | mysql_mutex_lock(&element->LOCK_table_share); |
| 354 | /* Wait for MDL deadlock detector to complete traversing tdc.all_tables. */ |
| 355 | while (element->all_tables_refs) |
| 356 | mysql_cond_wait(&element->COND_release, &element->LOCK_table_share); |
| 357 | element->all_tables.push_front(table); |
| 358 | mysql_mutex_unlock(&element->LOCK_table_share); |
| 359 | |
| 360 | mysql_mutex_lock(&tc[i].LOCK_table_cache); |
| 361 | if (tc[i].records == tc_size) |
| 362 | { |
| 363 | if ((LRU_table= tc[i].free_tables.pop_front())) |
| 364 | { |
| 365 | LRU_table->s->tdc->free_tables[i].list.remove(LRU_table); |
| 366 | /* Needed if MDL deadlock detector chimes in before tc_remove_table() */ |
| 367 | LRU_table->in_use= thd; |
| 368 | mysql_mutex_unlock(&tc[i].LOCK_table_cache); |
| 369 | /* Keep out of locked LOCK_table_cache */ |
| 370 | tc_remove_table(LRU_table); |
| 371 | } |
| 372 | else |
| 373 | { |
| 374 | tc[i].records++; |
| 375 | mysql_mutex_unlock(&tc[i].LOCK_table_cache); |
| 376 | } |
| 377 | /* Keep out of locked LOCK_table_cache */ |
| 378 | status_var_increment(thd->status_var.table_open_cache_overflows); |
| 379 | } |
| 380 | else |
| 381 | { |
| 382 | tc[i].records++; |
| 383 | mysql_mutex_unlock(&tc[i].LOCK_table_cache); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | |
| 388 | /** |
no test coverage detected